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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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
Super User
Super User

@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
Super User
Super User

@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] )

 

@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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors