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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

YTD Change

Hi,

I have a table like below:-

Current BalanceDate              Deal  Price  Value
3412/14/2022A703
2312/14/2022A602
2312/14/2022A5058
2312/14/2022B7010
9812/14/2022B603
6512/14/2022B506
4312/14/2022C708
2212/14/2022C609
4412/14/2022C504

 

I want to add a calculated column YTD change which is calculated as follows:-

 

  • For Deal A for Price 70 >> Filter the table for Deal A and Price 70 and then Value for Latest Date minus Value for First Date in the year
  • For Deal A for Price 60 >> Filter the table for Deal A and Price 60 and then Value for Latest Date minus Value for First Date in the year
  • For Deal A for Price 50 >> Filter the table for Deal A and Price 50 and then Value for Latest Date minus Value for First Date in the year

and so on........

 

Need help with the DAX formula to create this column please

2 ACCEPTED SOLUTIONS
Greg_Deckler
Community Champion
Community Champion

@Anonymous This is essentially MTBF. Try this:

Column = 
  VAR __Deal = [Deal]
  VAR __Price = [Price]
  VAR __FirstDate = MINX(FILTER('Table', [Deal] = __Deal && [Price] = __Price), [Date])
  VAR __LastDate = MAXX(FILTER('Table', [Deal] = __Deal && [Price] = __Price), [Date])
  VAR __FirstValue = MINX(FILTER('Table', [Deal] = __Deal && [Price] = __Price && [Date] = __FirstDate), [Value])
  VAR __LastValue = MINX(FILTER('Table', [Deal] = __Deal && [Price] = __Price && [Date] = __LastDate), [Value])
  VAR __Result = __LastValue - __FirstValue
RETURN
  __Result


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

negi007
Community Champion
Community Champion

@Anonymous  in this case,

first create a calc column in the orginal table

Deal_Date = 'Table'[Deal]&"|"&'Table'[Date]

negi007_1-1671191165789.png

 

then you can create another calc table from the main table like below

 

negi007_0-1671191076027.png

 then create below colums in the new table

Deal_Min_Date = Min_Max_value_2[Deal] & "|" & Min_Max_value_2[Min Date]
Deal_Max_Date = Min_Max_value_2[Deal] & "|" & Min_Max_value_2[max Date]
Min_Date_Value = LOOKUPVALUE('Table'[Value],'Table'[Deal_Date],Min_Max_value_2[Deal_Min_Date])
Max_Date_Value = LOOKUPVALUE('Table'[Value],'Table'[Deal_Date],Min_Max_value_2[Deal_Max_Date])
Max-Min = Min_Max_value_2[Max_Date_Value]-Min_Max_value_2[Min_Date_Value]
 
please note that you need all above columns, you can combine them in one dax column to have a clean view. just for illustration purpose, i have added all columns
 
also attached pbix file.



Did I answer your question? Mark my post as a solution!
Appreciate your Kudos



Proud to be a Super User!


Follow me on linkedin

View solution in original post

5 REPLIES 5
negi007
Community Champion
Community Champion

@Anonymous  in this case,

first create a calc column in the orginal table

Deal_Date = 'Table'[Deal]&"|"&'Table'[Date]

negi007_1-1671191165789.png

 

then you can create another calc table from the main table like below

 

negi007_0-1671191076027.png

 then create below colums in the new table

Deal_Min_Date = Min_Max_value_2[Deal] & "|" & Min_Max_value_2[Min Date]
Deal_Max_Date = Min_Max_value_2[Deal] & "|" & Min_Max_value_2[max Date]
Min_Date_Value = LOOKUPVALUE('Table'[Value],'Table'[Deal_Date],Min_Max_value_2[Deal_Min_Date])
Max_Date_Value = LOOKUPVALUE('Table'[Value],'Table'[Deal_Date],Min_Max_value_2[Deal_Max_Date])
Max-Min = Min_Max_value_2[Max_Date_Value]-Min_Max_value_2[Min_Date_Value]
 
please note that you need all above columns, you can combine them in one dax column to have a clean view. just for illustration purpose, i have added all columns
 
also attached pbix file.



Did I answer your question? Mark my post as a solution!
Appreciate your Kudos



Proud to be a Super User!


Follow me on linkedin

Greg_Deckler
Community Champion
Community Champion

@Anonymous This is essentially MTBF. Try this:

Column = 
  VAR __Deal = [Deal]
  VAR __Price = [Price]
  VAR __FirstDate = MINX(FILTER('Table', [Deal] = __Deal && [Price] = __Price), [Date])
  VAR __LastDate = MAXX(FILTER('Table', [Deal] = __Deal && [Price] = __Price), [Date])
  VAR __FirstValue = MINX(FILTER('Table', [Deal] = __Deal && [Price] = __Price && [Date] = __FirstDate), [Value])
  VAR __LastValue = MINX(FILTER('Table', [Deal] = __Deal && [Price] = __Price && [Date] = __LastDate), [Value])
  VAR __Result = __LastValue - __FirstValue
RETURN
  __Result


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

Hi, I have a table like below:

 

DateSectorValue
1/7/2015A44
1/14/2015A56
1/21/2025A7
1/28/2015A8
1/7/2015B3
1/14/2015B4
1/21/2025B67
1/28/2015B54
1/7/2015C66
1/14/2015C43
1/21/2025C2
1/28/2015C1

 

I want to create a summary table where I show the WoW change and MoM change from the latest date for every sector. I am having a hard time writing the correct DAX code to calculate both of these metrics. Please help.

 

Thanks,

 

Anonymous
Not applicable

@Greg_Deckler , one question:

To calculate variable _First Value, you are using a min function on the filtered table.

If I have data for both 2021 and 2022, would not this variable pick 2021 value instead of first date of 2022 to calculate YTD?

Anonymous
Not applicable

Thanks, this was perfect!

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.