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

October 28 & 29: Experts share their secrets on how to pass the Fabric Analytics Engineer certification exam—live. Learn more

Reply
saanchi2804
Helper I
Helper I

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

@saanchi2804 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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

negi007
Community Champion
Community Champion

@saanchi2804  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

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

@saanchi2804 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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

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,

 

@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?

Thanks, this was perfect!

Helpful resources

Announcements
OCT PBI Update Carousel

Power BI Monthly Update - October 2024

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

October NL Carousel

Fabric Community Update - October 2024

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