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
gdxy
Helper I
Helper I

DAX in KPI

Hi,

 

I would like to have a measure to present this idea but I don't really know how to do it with DAX, please see if it is feasible or not, thank you.

 

if year == 2021:

  target_score = 2021's score

else:

  target_score = year-1's score

 

For example, if the slicer selects 2021, the comparison could be (+0.0) if the slicer selects 2022. the KPI visual will compare the score of 2022 vs 2021 (2022-1). I would like to put the measure to the Target field in the KPI visual.

gdxy_0-1667734057746.png

 

 

 

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@gdxy , Create a separate year/date table and have a measure like

 


//Only year vs Year, not a level below

This Year = CALCULATE(sum('Table'[Qty]),filter(ALL('Date'),'Date'[Year]=max('Date'[Year])))
Last Year = CALCULATE(sum('Table'[Qty]),filter(ALL('Date'),'Date'[Year]=max('Date'[Year])-1))
diff = [This Year]-[Last Year ]
diff % = divide([This Year]-[Last Year ],[Last Year ])

 

Time Intelligence, DATESMTD, DATESQTD, DATESYTD, Week On Week, Week Till Date, Custom Period on Period,
Custom Period till date: https://youtu.be/aU2aKbnHuWs&t=145s

Power BI — Year on Year with or Without Time Intelligence
https://medium.com/@amitchandak.1978/power-bi-ytd-questions-time-intelligence-1-5-e3174b39f38a
https://www.youtube.com/watch?v=km41KfM_0uA

View solution in original post

4 REPLIES 4
amitchandak
Super User
Super User

@gdxy , Create a separate year/date table and have a measure like

 


//Only year vs Year, not a level below

This Year = CALCULATE(sum('Table'[Qty]),filter(ALL('Date'),'Date'[Year]=max('Date'[Year])))
Last Year = CALCULATE(sum('Table'[Qty]),filter(ALL('Date'),'Date'[Year]=max('Date'[Year])-1))
diff = [This Year]-[Last Year ]
diff % = divide([This Year]-[Last Year ],[Last Year ])

 

Time Intelligence, DATESMTD, DATESQTD, DATESYTD, Week On Week, Week Till Date, Custom Period on Period,
Custom Period till date: https://youtu.be/aU2aKbnHuWs&t=145s

Power BI — Year on Year with or Without Time Intelligence
https://medium.com/@amitchandak.1978/power-bi-ytd-questions-time-intelligence-1-5-e3174b39f38a
https://www.youtube.com/watch?v=km41KfM_0uA

Not sure why, but when I use
Last Year = CALCULATE(sum('university average (3)'[Value]),filter(ALL('year'),'year'[year]=MAX('year'[year])-1))
nothing is shown

Here are my tables:

gdxy_0-1667828676467.png

gdxy_2-1667828795724.png

 

 

 

I assume when I put the measure to the 'Target' field, if the year is 2021, the value will be the score in 2021, when the year is 2022 or above, the value will be the score of last year.

Sorry, I figured out the reason, the data type is text in one of my data fields.

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