Forum Discussion
Calculate Threshold Analysis
- 3 years ago
Step 1 - Transform your Month only column to a full date.
- Sep 2022 becomes 9/1/2022.
- Feb 2023 becomes 2/1/2023
This is easily done in Power Query Editor.
Step 2 - Also in Power Query Editor, select all the month columns & unpivot them so that instead of a separate column for each month-year, you now only have 1 column for "Date" & 1 column for "Value" (or whatever you want to rename it).
Step 3 - In the model, create the 1:* relationship between 'Date'[Date] & 'Data'[Date]
Step 4 Create a new measure called _B4PrevMONTH V2 .
This resolves the issue of (2 - 2 = 0) the invalid month number.
You can upload a PBIX to Google Drive, make it public & then share the link here on forums.
This should resolve the issue with your blank values for the "2 months ago" measure.
Regards,
Nathan
I'm not sure I completely understand.
1) Are the numbers in the rows of the month columns actual data? Or are they calculations? Do you have a test data set sample so that we could look at an isolated example of the problem?
2) If I understand correctly:
- The [_PrevMONTH] measure works no problem.
- The [_B4PrevMONTH] measure does NOT work, & returns only BLANKS.
Is it possible for you to include a screenshot of the visual where you are including this measure & getting blanks so we can get an idea of the filter context?
3) How did you create your calendar table? If by DAX, can you share the DAX used? What is the start date & end date?
NOTE: It will not be sufficient to only have month. For example, if the current month is Feb (month #2) & you try to subtract 2, you'll get 0, which is not a valid month.
Regards,
Nathan
1. It's actual data aggregated for each month
2. I added a few things in the calendar by DAX, but imported most.
Feb #2 - 2 months = 0 totally makes sense! Can you help with the work around?
How can I upload the powerbi file?
| TYPE | DATE | MONTH | YEAR | DAY |
| CASE2 | 2/20/2023 | FEB | 2022 | FRI |
| CASE2 | 1/31/2023 | JAN | 2022 | MON |
| CASE2 | 1/21/2023 | JAN | 2022 | FRI |
| CASE2 | 12/24/2022 | DEC | 2022 | FRI |
| CASE2 | 12/24/2022 | DEC | 2022 | SAT |
| CASE3 | 12/11/2022 | DEC | 2022 | MON |
| CASE1 | 11/8/2022 | NOV | 2022 | FRI |
| CASE2 | 11/20/2022 | NOV | 2022 | FRI |
| CASE1 | 10/17/2022 | OCT | 2022 | MON |
Here's what the sample look like