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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
pborah
Impactful Individual
Impactful Individual

How to get the count for the whole week and previous week when filtering on a certain date?

I'm recreating an SSRS report where requirement is that the user wants to see the counts for the whole and the week before when filtering for a certain date. This functionality should hold even when selecting a date in the middle of the week. Week begins on a Sunday. E.g. If I filter for June 1st 2022 which is a Wednesday, I should get two sets of counts, one for current week May 29th 2022 (Sunday)- June 4th 2022 (Saturday), and one for previous week - May 22nd 2022 - May 28th 2022. Below is a sample result from the SSRS report. 

 

pborah_0-1654092274471.png

 

I do have a calendar table 

 

pborah_1-1654092322513.png

 

Unfortunately I cannot share the pbix due to confidential data. In SSRS the date is the parameter as opposed to filter in Power BI.

5 REPLIES 5
CNENFRNL
Community Champion
Community Champion

It's enough to use a single WEEKNUM() in calendar table,

CNENFRNL_0-1654099279513.png

 


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

pborah
Impactful Individual
Impactful Individual

@CNENFRNL Can you please explain how do I count rows of the table linked to this calendar table with the WK_Previous and WK_Current measures you provided? Using CALCULATE to count rows witrh the measures as filters results in an error.

CNENFRNL
Community Champion
Community Champion

These measures only demonstrate to you which dates in the calendar table are exactly chosen for further calculations.

=
CALCULATE(
    COUNTROWS( 'Related Table' ),
    CALCULATETABLE( DATES, REMOVEFILTERS(), DATES[WK] = MAX( DATES[WK] ) )
)

 


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

pborah
Impactful Individual
Impactful Individual

@CNENFRNL Thank you for your suggestions but I'm sorry none of these are working for me. The week start date and end date for both current and previous weeks are off by one day when I use the measures you suggested, i.e. the week goes from Monday to Sunday, even though in my date date table, my week starts on a Sunday and ends on a Monday and I've used the appropriate parameter for that in WEEKNUM which is '1'.

 

But in any case, the ability to show these dates is of secondary importance in the report. What is more important is getting the counts right, which again, the measure you provided doesn't work. Additionally, the ability to select a date from a calendar type slicer as opposed to a list or a dropdown is also quite important to keep the user experience similar to the old SSRS report. The "between", "before", "after" options in the slicer do not fulfil the requirement of the report. 

 

So if you still want to try, let me give you a proper context of the report requirement -

 

I have a transactions table with dates which is linked to a calendar table. The user has to select any arbitrary date from a calendar type slicer/visual. Given that selection, the report is supposed to show count of transactions for the whole week containing that selected date, and the previous week. 

 

So an example of the transaction data would be as follows - 

 

Transaction_ID   District  Date
1                    1     2022/05/01
2                    1     2022/05/02
3                    4     2022/05/02
4                    2     2022/05/03

 

 

I hope this gives you a clearer idea of what I'm looking for.

 

pborah
Impactful Individual
Impactful Individual

Thanks. I'm just leaving a note here so that admins don't close this thread saying solution was found. I will test it out and let you know whether it worked. I'll figure out how to do the counts using these measures.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

Feb2025 NL Carousel

Fabric Community Update - February 2025

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