Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
milkynight
Helper I
Helper I

How to subtract a dax measure to a value of imported column?

Hi all,

 

I have a simple question that I only encounter now: Why can't I subtract a measure to an imported column?

Below example that Actual sales (a dax measure) and Target (imported number) and desired result of Var (Actual Sales - Target)

 

I normally have Measure - Measure and it's simple, but what shall I do in this situation? Thank you.

NameTargetActual salesVar
A100%100%0%
B100%80%-20%
C100%70%-30%
2 ACCEPTED SOLUTIONS
ERD
Community Champion
Community Champion

@milkynight ,

if I correctly understand your situation, you need to substract measure from the current value:

measure =
VAR currentTarget = SELECTEDVALUE ( T[Target] )
RETURN
    [measureName] - currentTarget

If this post helps, then please consider Accept it as the solution ✔️to help the other members find it more quickly.

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. Appreciate your Kudos.

Check out my latest demo report in the data story gallery.

Stand with Ukraine!


Here are official ways you can support Ukraine financially (accounts with multiple currencies):
1) Support the Armed Forces of Ukraine: https://bank.gov.ua/ua/about/support-the-armed-forces
2) Come Back Alive foundation: https://www.comebackalive.in.ua/

Thank you!

View solution in original post

Hi @milkynight 

 

I'm glad you found the solution.

You can not use a column name in the measure to find the value; you must wrap the column in an aggregation function like MIN, MAX, SUM, AVERAGE, etc.

In your case, because you used the Name column, if you use Min or Max, it will return the value corresponding to that row.

https://www.sqlbi.com/articles/row-context-and-filter-context-in-dax/

https://www.sqlbi.com/articles/calculated-columns-and-measures-in-dax/

 

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.

Appreciate your Kudos!!

 

View solution in original post

7 REPLIES 7
VahidDM
Super User
Super User

Hi @milkynight 

 

Try this:

Var=
Var _AS = [Actual sales]
Var _Tar = max(table(Target))
return
_AS-_Tar

 

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.

Appreciate your Kudos!!

 

@VahidDM thanks, I guess your DAX can be shortened to: Var = [Actual Sales] - max(table [Target])?

Both long and short version works, but I'm curious why we use max for Target?

Hi @milkynight 

 

I'm glad you found the solution.

You can not use a column name in the measure to find the value; you must wrap the column in an aggregation function like MIN, MAX, SUM, AVERAGE, etc.

In your case, because you used the Name column, if you use Min or Max, it will return the value corresponding to that row.

https://www.sqlbi.com/articles/row-context-and-filter-context-in-dax/

https://www.sqlbi.com/articles/calculated-columns-and-measures-in-dax/

 

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.

Appreciate your Kudos!!

 

ERD
Community Champion
Community Champion

@milkynight ,

if I correctly understand your situation, you need to substract measure from the current value:

measure =
VAR currentTarget = SELECTEDVALUE ( T[Target] )
RETURN
    [measureName] - currentTarget

If this post helps, then please consider Accept it as the solution ✔️to help the other members find it more quickly.

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. Appreciate your Kudos.

Check out my latest demo report in the data story gallery.

Stand with Ukraine!


Here are official ways you can support Ukraine financially (accounts with multiple currencies):
1) Support the Armed Forces of Ukraine: https://bank.gov.ua/ua/about/support-the-armed-forces
2) Come Back Alive foundation: https://www.comebackalive.in.ua/

Thank you!

Thanks you, this solution is good for me

@ERD thanks so much, it works nicely.

Just curious, does the first clause mean to convert the imported value to Measure? I tried with VALUES originally and it didn't work 

VAR currentTarget = SELECTEDVALUE ( T[Target] )

 

ERD
Community Champion
Community Champion

@milkynight , SELECTEDVALUE function is used in a measure to return a value when the context for ColumnName has been filtered down to one distinct value. I'd say read and use column value in further calculations instead of 'convert'. 

You can read about the function here: https://dax.guide/selectedvalue/

Also you could use MAX function instead. In this particular case it will do the same.

If this post helps, then please consider Accept it as the solution ✔️to help the other members find it more quickly.

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. Appreciate your Kudos.

Check out my latest demo report in the data story gallery.

Stand with Ukraine!


Here are official ways you can support Ukraine financially (accounts with multiple currencies):
1) Support the Armed Forces of Ukraine: https://bank.gov.ua/ua/about/support-the-armed-forces
2) Come Back Alive foundation: https://www.comebackalive.in.ua/

Thank you!

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.