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
susan_d_10
Frequent Visitor

How to determine a change in value for an attribute over a time period

I am very new to this, so i am hoping my explanation makes sense.       I am trying to show the monthly variance of a part attribute.    This attribute is not a measure but just a number and there can be daily records in the cube.      I am using Live Connection   For EOM processing a flag is set to indicate that the value on the last day of the month against the part is that month's value.    I am trying to get something like this below, so i can show any variances.    I have very limited experience with DAX and tried PREVIOUSMONTH but this will only let me SUM the number value.   I need only the one value that has the EOM processing flag against it.   Any ideas would be great, so far i have spent a number of days on this.

 

Part            Current Mth        Previous Mth      % Diff

widget 1     5.5                       4.5                       18%

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

If you have a calendar, datesmtd and toyalmtd can help. Option 2 and 3, is the one work for you

// MTD and LMTD
MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD('Date'[Date]))
last MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(dateadd('Date'[Date],-1,MONTH)))
last MTD (complete) Sales =  CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(ENDOFMONTH(dateadd('Date'[Date],-1,MONTH))))

// MTD and LMTD, if you have month end filter

MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD('Date'[Date]),Sales[EOM]=1)
last MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(dateadd('Date'[Date],-1,MONTH)),Sales[EOM]=1)
last MTD (complete) Sales =  CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(ENDOFMONTH(dateadd('Date'[Date],-1,MONTH))),Sales[EOM]=1)

// MTD and LMTD, filter for month end
MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),filter('Date','Date'[Date]=endofmonth('Date'[Date])))
MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),filter('Date','Date'[Date]=endofmonth(dateadd('Date'[Date],-1,MONTH))))

 

To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :
https://radacad.com/creating-calendar-table-in-power-bi-using-dax-functions
https://www.archerpoint.com/blog/Posts/creating-date-table-power-bi
https://www.sqlbi.com/articles/creating-a-simple-date-table-in-dax/

View solution in original post

6 REPLIES 6
Greg_Deckler
Super User
Super User

Hmm, if this is a LIVE connection, I am not certain that time intelligence functions are supported. I know they are not for Direct Query and I *think* this also covers Live connections. If that is indeed the case, See if my Time Intelligence the Hard Way provides a different way of accomplishing what you are going for.

https://community.powerbi.com/t5/Quick-Measures-Gallery/Time-Intelligence-quot-The-Hard-Way-quot-TIT...


@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
amitchandak
Super User
Super User

If you have a calendar, datesmtd and toyalmtd can help. Option 2 and 3, is the one work for you

// MTD and LMTD
MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD('Date'[Date]))
last MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(dateadd('Date'[Date],-1,MONTH)))
last MTD (complete) Sales =  CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(ENDOFMONTH(dateadd('Date'[Date],-1,MONTH))))

// MTD and LMTD, if you have month end filter

MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD('Date'[Date]),Sales[EOM]=1)
last MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(dateadd('Date'[Date],-1,MONTH)),Sales[EOM]=1)
last MTD (complete) Sales =  CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(ENDOFMONTH(dateadd('Date'[Date],-1,MONTH))),Sales[EOM]=1)

// MTD and LMTD, filter for month end
MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),filter('Date','Date'[Date]=endofmonth('Date'[Date])))
MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),filter('Date','Date'[Date]=endofmonth(dateadd('Date'[Date],-1,MONTH))))

 

To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :
https://radacad.com/creating-calendar-table-in-power-bi-using-dax-functions
https://www.archerpoint.com/blog/Posts/creating-date-table-power-bi
https://www.sqlbi.com/articles/creating-a-simple-date-table-in-dax/

Thank you for this.  As soon as i use CALCULATE(SUM.....) it is summing up the values for the entire month.    there is a part price every day of the month the only value that i need is the price that has EOM snapshot flag set to Y.   I am very new at this and trying to work out how to attach an excel file.   But sample below. 

Snapshot DateEOM Snapshot FlagPartPrice     
31/01/2020YWidget111 Sample   
23/01/2020NWidget111.75 Jan   
15/01/2020NWidget111.75 PartCurr MthPrev MthDiff
10/01/2020NWidget111.25  JanDec 
9/01/2020NWidget111.25 Widget 11111.54.50%
8/02/2020NWidget111.25 Widget27.7579.60%
7/02/2020NWidget111.25     
6/02/2020NWidget111.25     
5/02/2020NWidget111.25     
4/02/2020NWidget111.25     
3/02/2020NWidget111.5     
2/02/2020NWidget111.5     
1/02/2020NWidget111.5     
31/12/2019YWidget111.5     
25/02/2020NWidget27     

@susan_d_10 

I think sample do not have enough data for Widget two. Please find solution attached(Link below signature)

Thank you very much.    This is so close.   It works on the data provided and that may be my mistake.   On our data the MAX is making it return the highest number, not the number that was the last at EOM.    I will keep working with these and i am sure i will crack it.

I have tried all of these but to no avail.     No matter what i do with the CALCULATE i immediately get every day's price, instead of only the one that is the EOM figure

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.