Forum Discussion
Diff between selected and previous period
Hi Experts,
I've closed the previous one as solved, but when I add all filter the formula is not working again. So:
I have [Date] column with only start of the week dates in it. I need to calculate the diff between selected and previous period. (The period is selected by the user.) There are filters by market, age, gender, brand ect. I added one slicer by period type and one with corresponding dates. The following measure is not showing the correct last period and I don't know how to fixed it:
Also, the previous period must show previous period regardless of the filter selection.
This time I'm attaching a pbix.
Best Regards!
Hi v-kpoloju-msft and techies ,
I managed to get the measure to work the way I needed it to:
Previous Period Value =VAR PeriodType = MAX('Period'[Period Type])VAR PeriodsBack = SELECTEDVALUE('No of Periods'[Value])VAR PrevRank = [Switch MAX Period Rank] - PeriodsBackVAR CurrentMarket = SELECTEDVALUE('data'[Market])VAR CurrentCategory = SELECTEDVALUE('data'[Category])VAR CurrentBrand = SELECTEDVALUE('data'[Brand])RETURNIF(ISBLANK(PrevRank),BLANK(),CALCULATE([Switch KPIs],FILTER(ALL('data'),SWITCH(PeriodType,"Week", 'data'[Wave] = PrevRank,"Month", 'data'[Month Rank] = PrevRank,"Quarter", 'data'[Quarter Rank] = PrevRank,"Year", 'data'[Year Rank] = PrevRank) &&'data'[Market] = CurrentMarket &&'data'[Category] = CurrentCategory &&'data'[Brand] = CurrentBrand &&NOT(ISFILTERED('data'[Age])) &&NOT(ISFILTERED('data'[Children])))))
Probably there were too many unknowns and I didn't explain things the right way, but I really appreciate your time.
Thanks a lot!
HO
21 Replies
- techiesSuper UserPrevious Period Value =VAR SelectedDate = SELECTEDVALUE('Date Parameter'[Date Selection])VAR PreviousDate =CALCULATE(MAX('data'[Date]),ALL('data'),'data'[Date] < SelectedDate)RETURNCALCULATE(SUM('data'[Value]),ALLSELECTED('data'),'data'[Date] = PreviousDate)
- HOrakovaHelper I
Hi v-kpoloju-msft and techies ,
I managed to get the measure to work the way I needed it to:
Previous Period Value =VAR PeriodType = MAX('Period'[Period Type])VAR PeriodsBack = SELECTEDVALUE('No of Periods'[Value])VAR PrevRank = [Switch MAX Period Rank] - PeriodsBackVAR CurrentMarket = SELECTEDVALUE('data'[Market])VAR CurrentCategory = SELECTEDVALUE('data'[Category])VAR CurrentBrand = SELECTEDVALUE('data'[Brand])RETURNIF(ISBLANK(PrevRank),BLANK(),CALCULATE([Switch KPIs],FILTER(ALL('data'),SWITCH(PeriodType,"Week", 'data'[Wave] = PrevRank,"Month", 'data'[Month Rank] = PrevRank,"Quarter", 'data'[Quarter Rank] = PrevRank,"Year", 'data'[Year Rank] = PrevRank) &&'data'[Market] = CurrentMarket &&'data'[Category] = CurrentCategory &&'data'[Brand] = CurrentBrand &&NOT(ISFILTERED('data'[Age])) &&NOT(ISFILTERED('data'[Children])))))
Probably there were too many unknowns and I didn't explain things the right way, but I really appreciate your time.
Thanks a lot!
HO - HOrakovaHelper I
Actually I'm getting error message "The file type (.pbix) is not supported."
- HOrakovaHelper I
I don't know if this help.
- v-kpoloju-msftCommunity Support
Hi HOrakova,
Thank you for reaching out to the Microsoft fabric community forum. Thank you techies, for your inputs on this issue.
After thoroughly reviewing the details you provided, I was able to reproduce the scenario, and it worked on my end. I have used it as sample data on my end and successfully implemented it.
Preious Period column dax measure:Previous Period =VAR CurrentPeriod = MAX(data[Switch Period]) -- Identify the current period selectedRETURNCALCULATE(SUM(data[Value]),FILTER(ALL(data), -- Ignores all filters applied except datedata[Switch Period] = CurrentPeriod - 1 -- Finds the previous period))
I am also including .pbix file for your better understanding, please have a look into it:
I hope this could resolve your issue, if you need any further assistance, feel free to reach out. If this post helps, then please give us ‘Kudos’ and consider Accept it as a solution to help the other members find it more quickly.
Thank you for using Microsoft Community Forum- HOrakovaHelper I
Hi v-kpoloju-msft ,
Thank you for stepping in. I use a slicer parameter for the type of period (week/month/quarted/year) and another one for the respective period. In your formula I was able to switch the last row with:
SELECTEDVALUE(Period[Period Type]) = CurrentPeriod - 1
but an error fetching data occurs.