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

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.

Reply
Smokey24
Helper I
Helper I

Distinct count previous month/week with IF and FIlter Statement on Custom Calender

Hi all,

 

I am using a 5-4-4 calender and in a Matrix I am showing in one column the distinctcount amount of outlets and the column next to it should compare the current amount with the previous month and previous week.

 

Looks like this:

 

                 Amount    Prev. Amount 

   Jan            100

(Week 1)      120
(Week 2)        80                   120

(Week 3)        90                     80

   Feb            120                   100

(Week 4)         x                       90
(Week 5)         x                       

(Week 6)         x

 

To compare the week to the previous week I simply use Time intelligence:

 

CALCULATE( DISTINCTCOUNT('FactTable Outlets'[FK_Outlet]);
DATEADD( 'MasterCalendar'[Date]; -7; DAY ))
 
For the months and sum calculations I use this measure:
VAR vActMonth = SELECTEDVALUE('MasterCalendar'[5-4-4 Month number])
VAR vActYear = SELECTEDVALUE('MasterCalendar'[5-4-4 Year])
VAR vMaxMonthNum = CALCULATE(MAX('MasterCalendar'[5-4-4 Month number]); ALL('MasterCalendar'))
VAR vCalc =
       IF(HASONEVALUE('MasterCalendar'[5-4-4 Month number]);
           SUMX(FILTER(ALL('MasterCalendar');
              IF(vActMonth = 1;
                 'MasterCalendar'[5-4-4 Month number] = vMaxMonthNum && 'MasterCalendar'[5-4-4 Year] = vActYear-1;
                 'MasterCalendar'[5-4-4 Month number] = vActMonth-1 && 'MasterCalendar'[5-4-4 Year] = vActYear));
Measure); BLANK())
 
Now instead of the SUMX I am trying to use the DISTINCTCOUNT so I get the right result for the month row.
 
Could you help me out?
 
Thanks!
 
 
1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

Please refer to this file to compare the weeks. It uses week Rank. You have to use the same logic even to compare period of 5-4-4 , just name make sure you have something to create Rank

https://www.dropbox.com/s/d9898a48e76wmvl/sales_analytics_weekWise.pbix?dl=0

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

3 REPLIES 3
amitchandak
Super User
Super User

Please refer to this file to compare the weeks. It uses week Rank. You have to use the same logic even to compare period of 5-4-4 , just name make sure you have something to create Rank

https://www.dropbox.com/s/d9898a48e76wmvl/sales_analytics_weekWise.pbix?dl=0

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Greg_Deckler
Community Champion
Community Champion

What exactly is the issue?


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

In a matrix I am trying to compare the month to the month before.

One Hierachy level below are the weeks and there I am comparing the week to the week before. Here I just use time intelligence.

 

But since I am using a 5-4-4 calender I can't use time intelligence to compare the months.

 

I do have a measure to show me the value of the previous month which looks like this:

 

VAR vActMonth = SELECTEDVALUE('MasterCalendar'[5-4-4 Month number])
VAR vActYear = SELECTEDVALUE('MasterCalendar'[5-4-4 Year])
VAR vMaxMonthNum = CALCULATE(MAX('MasterCalendar'[5-4-4 Month number]); ALL('MasterCalendar'))
RETURN
     IF(HASONEVALUE('MasterCalendar'[5-4-4 Month number]);
        SUMX(FILTER(ALL('MasterCalendar');
        IF(vActMonth = 1;
       'MasterCalendar'[5-4-4 Month number] = vMaxMonthNum && 'MasterCalendar'[5-4-4 Year] = vActYear-1;
       'MasterCalendar'[5-4-4 Month number] = vActMonth-1 && 'MasterCalendar'[5-4-4 Year] = vActYear));
       Measure); BLANK())

 

Since I am using DISINCTCOUNT I would need a new logic.

That's why I asked if it is possible to some how use DISTINCTCOUNT instead of SUMX or if there is a way to combine these two.

 

So I need to DISTINCTCOUNT with a FILTER and an IF statement.

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors