Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
DEMDEJ
Frequent Visitor

Calculate Threshold Analysis

This is what I want to do:

CaptureX.JPG

 

But I have two issues that I have been stuck with:

1. When calculating my month fields, I can only go back to the previous month using this formula, else, it's blank.

 

_PrevMONTH = var _CURRENTMONTH= MONTH(TODAY())
  RETURN
  CALCULATE(COUNT('Official'[nature]),FILTER('Official',MONTH([DATE])=_CURRENTMONTH -1))
 -------------------------------
The formula below shows blanks for all values.
_B4PrevMONTH = var _CURRENTMONTH= MONTH(TODAY())
  RETURN
  CALCULATE(COUNT('Official'[nature]),FILTER('Official',MONTH([DATE])=_CURRENTMONTH -2))
 
My goal is to create a measure for all calculations, but I'm open.
 
2. My second issue that I cannot sort the months from most recent to oldest instead of chronological (Feb, Jan, Dec, Nov, Oct)
 
I've created a calendar table and joined it will my table, created sort bys, and still can't find a way to make it work.
 
Any assistance is greatly appreciated and I will give kudos!
1 ACCEPTED SOLUTION
WinterMist
Impactful Individual
Impactful Individual

@DEMDEJ 

 

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).

 

WinterMist_2-1677623535028.png

 

Step 3 - In the model, create the 1:* relationship between 'Date'[Date] & 'Data'[Date]

 

WinterMist_3-1677623626860.png

 

Step 4 Create a new measure called _B4PrevMONTH V2 .

This resolves the issue of (2 - 2 = 0) the invalid month number.

 

WinterMist_0-1677623225038.png

 

WinterMist_1-1677623273097.png

 

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

 

 

 

 

View solution in original post

5 REPLIES 5
WinterMist
Impactful Individual
Impactful Individual

@DEMDEJ 

 

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).

 

WinterMist_2-1677623535028.png

 

Step 3 - In the model, create the 1:* relationship between 'Date'[Date] & 'Data'[Date]

 

WinterMist_3-1677623626860.png

 

Step 4 Create a new measure called _B4PrevMONTH V2 .

This resolves the issue of (2 - 2 = 0) the invalid month number.

 

WinterMist_0-1677623225038.png

 

WinterMist_1-1677623273097.png

 

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

 

 

 

 

@WinterMist  Thanks so much for being such a great help! Do you mind sharing recommendations for becoming better at PowerBI?

You are AWESOME!

WinterMist
Impactful Individual
Impactful Individual

@DEMDEJ 

 

You are welcome.  Thanks for the kind words.

 

For improving in DAX, check the following thread:

https://community.powerbi.com/t5/DAX-Commands-and-Tips/How-to-learn-DAX-from-beginning-to-Advance/m-...

 

Regards,

Nathan

WinterMist
Impactful Individual
Impactful Individual

@DEMDEJ 

 

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

 

 

@WinterMist  

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?

 

CaptureX.JPG

 

TYPEDATEMONTHYEARDAY
CASE22/20/2023FEB2022FRI
CASE21/31/2023JAN2022MON
CASE21/21/2023JAN2022FRI
CASE212/24/2022DEC2022FRI
CASE212/24/2022DEC2022SAT
CASE312/11/2022DEC2022MON
CASE111/8/2022NOV2022FRI
CASE211/20/2022NOV2022FRI
CASE110/17/2022OCT2022MON

 

Here's what the sample look likeCaptureXX.JPG

 

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors