# Asset original risk score vs context-driven risk score

**URL:** <https://discuss.rapid7.com/t/asset-original-risk-score-vs-context-driven-risk-score/35111>\
**Category:** InsightVM\
**Tags:** InsightVM, sql, queries\
**Created:** [March 26, 2024, 2:40pm UTC](https://discuss.rapid7.com/t/asset-original-risk-score-vs-context-driven-risk-score/35111 "2024-03-26T14:40:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![vfesik](https://discuss.rapid7.com/letter_avatar_proxy/v4/letter/v/dfb087/32.png) [@vfesik](https://discuss.rapid7.com/u/vfesik)\
**Post date:** [March 26, 2024, 2:40pm UTC](https://discuss.rapid7.com/t/asset-original-risk-score-vs-context-driven-risk-score/35111/1 "2024-03-26T14:40:21Z")

</div>

Dear community,

I faced with issue where I can’t see the context-driven score in sql query reports.  
If I sort assets by fa.riskscore I see only Original score. But I have a critical tags with Risk Score Adjustment to help prioritize asset management.  
However, I can’t find in documentation any way to see context-driven score.  
Do you have any idea how can I do it?

---

<div class="post-metadata">

**Author:** ![vfesik](https://discuss.rapid7.com/letter_avatar_proxy/v4/letter/v/dfb087/32.png) [@vfesik](https://discuss.rapid7.com/u/vfesik)\
**Post date:** [March 27, 2024, 8:55am UTC](https://discuss.rapid7.com/t/asset-original-risk-score-vs-context-driven-risk-score/35111/2 "2024-03-27T08:55:04Z")

</div>

So apparently -Context-driven risk score is not a field in the reporting data model, so to pull that, you’ll need to take the risk\_modifier from dim\_tag and the value from the tags applied to the asset and calculate that against the original risk score.

With little help of ChatGPT I was able to calculate the context-driven score inside the query like this:

WITH location\_tags AS (  
SELECT  
dta.asset\_id,  
string\_agg(dt.tag\_name, ', ') as location\_tags  
FROM  
dim\_tag dt  
JOIN dim\_tag\_asset dta ON dt.tag\_id = dta.tag\_id  
WHERE  
dt.tag\_type = ‘LOCATION’  
GROUP BY  
dta.asset\_id  
),  
owner\_tags AS (  
SELECT  
dta.asset\_id,  
string\_agg(dt.tag\_name, ', ') as owner\_tags  
FROM  
dim\_tag dt  
JOIN dim\_tag\_asset dta ON dt.tag\_id = dta.tag\_id  
WHERE  
dt.tag\_type = ‘OWNER’  
GROUP BY  
dta.asset\_id  
),  
criticality\_tags AS (  
SELECT  
dta.asset\_id,  
string\_agg(dt.tag\_name, ', ') as criticality\_tags,  
risk\_modifier::double precision – Cast risk\_modifier to double precision  
FROM  
dim\_tag dt  
JOIN dim\_tag\_asset dta ON dt.tag\_id = dta.tag\_id  
WHERE  
dt.tag\_type = ‘CRITICALITY’  
GROUP BY  
dta.asset\_id,  
dt.risk\_modifier  
)  
SELECT  
da.ip\_address,  
da.host\_name,  
lt.location\_tags AS Application, – Renaming location\_tags to Application  
ot.owner\_tags AS Regulated, – Renaming owner\_tags to Regulated  
crit.criticality\_tags,  
fa.riskscore AS “Risk Score”,  
CAST(fa.riskscore::double precision \* crit.risk\_modifier AS NUMERIC(10,0)) AS “Adjusted Risk Score” – rounding the Adjusted Risk Score to 0 decimal places  
FROM  
dim\_asset da  
LEFT JOIN location\_tags lt USING (asset\_id)  
LEFT JOIN owner\_tags ot USING (asset\_id)  
LEFT JOIN criticality\_tags crit USING (asset\_id)  
JOIN fact\_asset fa ON da.asset\_id = fa.asset\_id
