Forum Discussion
Last period Data based on Date/Quarter/Month/Week Filter selection
- 8 years ago
Its all about filter context, Try creating a lookupdate table with Just YEARMONTHSHORT values
YEARMONTHS = VALUES(date[YearMonthShort])
Relate that to your data table and set your slice on that.
If doesn't work, you could try NOT using a SLICER to select the month but instead use a disconnected slicer to have user select month, date or whatever and then use that SELECTEDVALUE of what the user selectes as teh desired period in your measures.
Use a disconnected slicer to harvest the users choice.
- Create a table using Enter Data
- Do NOT link or relate this table to your data
- Write a measure to harvest the users choice
- Write a Dynamic Measure using Switch(TRUE()) to calcualte based on that choice
| Period |
| Day |
| Week |
| Month |
| Quarter |
| Year |
Selected Period = SELECTEDVALUE(Periods[Period],"Day") // defaults to day if nothing selected
OIF_Value_EUR_Calc = Switch(TRUE(),
[Selected Period]="Day", calc for day,
[Selected Period]="Week", calc for week,
….)
Hi Seward12533,
Thank you so much for the reply. That would work. But I have one question, If user selects any of this slicer, Lets say user selects Month, then he should allow to select only 'Month filter' or if he selects Week, then he should see Week filter. Is it possible?
Because based on the selection, they want to see past period data. If user selects 'Feb 2018', he wants to see data from Feb -2017 to Feb 2018. (Last 12 months based on selection)
Regards,
Poonam
- Seward125338 years ago
Solution Sage
You would ahve to give me a better idea of what your data model and visuals look like.
If you just want to limit the data range based on the choice and then use other filters to further refine its a bit more complicated. In this case you don't want to put the logic into the measures but rather use Time Intelligence and dyanmic filter context of Power BI. The approach woudl be to write a meausure to calculate the EARLIEST_DATE and LATEST_DATE based on today's date (or selected daate) and the choice form the disconnected slicer. Then add a calcualted column to your date table called "Include" or something like that and test to see if the date on each row of the date table is in that range or not. Then use a Page filter to only include Include="YES". This will imit the scope of all the calcualtions to within the date range you calculate.
Hoep this helps.
- Anonymous8 years agoNot applicable
hI Seward12533,
I think the problem is different. Sorry, I just realized.
Just for testing purpose I changed my calculation to calculate last 30 days value.
OIF_Value_EUR_Calc =
CALCULATE (
SUM ( V_OPPORTUNITIES_OIF[OIF_Value_EUR] ),
DATESINPERIOD ( V_OPPORTUNITIES_PERIOD[Created_Date], MAX (V_OPPORTUNITIES_PERIOD[Created_Date]),-30, DAY )If this calculation is based on lowest aggregation level, if I select Month : July 2018, it should show me data from Jun-2018 to july-2018. But as I have selected 'Month' filter. it is showing the data only for July month. In the below screen shot,
'OIF_value_EUR_Calc' should show value from jun-2018 to july -2018 as I changed formula to calculate last 30 days value. but at the same time I have selected 'Month' filter, it is showing the data for '1st july 2018' to '11th july-2018' only. not calculating last 30 days. If I changed the same formula to claulate last 10 days value, it calulate data only for 5 days correctly as it is in same month. (See the 2nd screen shot). Do I have to ignore 'Month/Quarter/Week' selection in this case. but at the same time, I want to show the last period data based on filter selection only. What can be done in this case.
Thank you!
- Seward125338 years ago
Solution Sage
Thanks, that helps me understand what your trying to do. First for this to work correclty you need a date table and your Slicer has to filter your data table and NOT your DATA table (also if you build visuals you need to use the date fields (month/quarter/year etc) from your data table as well as rows/columns/axis on your visuals.
Assuming you have a date table try this where dimdate is your data table and dimdate[Date] is the primary key from your date table and is related to your V_OPPORTUNITIES_PERIOD[Created_Date] in the model
OIF_Value_EUR_Calc =
CALCULATE (
SUM ( V_OPPORTUNITIES_OIF[OIF_Value_EUR] ),dimdate,
DATESINPERIOD (dimdate[Date] , MAX (V_OPPORTUNITIES_PERIOD[Created_Date]),-30, DAY )Note, I have not used DATESINPERIOD before as I tend to use a more generic DAX pattern which can be handy if you want to do things like cumulative since the beginning of time.
CALCULATE(original measure,
Custom Calendar Table, // All not needed
FILTER(ALL(Custom Calendar Table),
logic to select a modified date range)
So in your situation
OIF_Value_EUR_Calc =VAR LastDate = MAX (V_OPPORTUNITIES_PERIOD[Created_Date]) RETURN
CALCULATE (
SUM ( V_OPPORTUNITIES_OIF[OIF_Value_EUR] ),dimdate,
FILTER(ALL(dimdate[Date]) , dimdate[date]<=LastDate&&dimdate[date]<=LastDate-30))