Forum Discussion
How to calculate difference between current quarter and previous quarter
- 3 years ago
Reddy5833 Try:
Measure = VAR __Current = SUM('Table'[usage]) VAR __CurrentQR = MAX('Table'[Quarter rank]) VAR __Previous = SUMX(FILTER(ALL('Table'),[Quarter rank] = __CurrentQR - 1),[usage]) VAR __Result = IF(__Previous = BLANK(),BLANK(),__Current - __Previous) RETURN __Result - 3 years ago
Greg_Deckler Thanks a lot, it works perfect..
- 3 years agoHi Greg_Deckler ,I got the answer to my question, I found it from your video ( MSHGQM - Power BI DAX - Don't Use CALCULATE!)Measure to be used when there are multiple categories.
Measure 1 =VAR __Site = VALUES('Sample'[Site Name])VAR __Current = sum('Sample'[Usage])VAR __Table = FILTER(ALLSELECTED('Sample'),'Sample'[Site Name] in __Site)VAR __CurrentQR = MAX('Sample'[YQRank])VAR __Previous = SUMX(FILTER(__Table,[YQRank] = __CurrentQR - 1), [Usage])VAR __Result = IF(__Current=BLANK(),"0",__Current - __Previous)RETURN__Result
Hi Greg_Deckler, I have usage data for 5 years, (around 1500 records), the table contains date field, formateed as date data type only, I want to calculate differnce of usage between current qtr and prvs qtr (same as i asked in previos question, but based on proper date field)
I'm using below measeu to calculate prev quarter usage,
measure to calculate diff: -- works fine when i connect with date table
sample data
result when connected with date dimension
Result when not connected with date
Reddy5833 This is because you are using CALCULATE. CALCULATE almost requires a star schema to work properly. CALCULATE has a really hard time dealing with single table data models so you get wacky results. See this video:
- Reddy58333 years ago
Helper II
Hi Greg_Deckler , I saw the video, it's brilliant.. Thanks a lot