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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
A_a_a
Helper III
Helper III

To count number of weeks based on slicer

Hi All,

 

I have an option to choose in filters years, months or weeks, depending what users need.

How can I create a measure to count weeks selected? for example if the user selects 'January to March', the measure will show 13 weeks or when the user selects just 2 weeks in week slicer, the measure will show 2, etc.

I have 3 slicers from the same dim date table:

 

A_a_a_0-1702285519137.png

 

Happy to change the layout if it is better to do the measure, for example:

A_a_a_1-1702285617106.png

 

 

 

Please support.

Thank you!

1 ACCEPTED SOLUTION
isjoycewang
Super User
Super User

Provide demo file and another DAX for reference:

 

WkCount = 
VAR _MinYear = MIN('Calendar'[Date].[Year])
VAR _MaxYear = MAX('Calendar'[Date].[Year])
VAR _MinMonth = MIN('Calendar'[Month])
VAR _MaxMonth = MAX('Calendar'[Month])
VAR _MinWeek = MIN('Calendar'[Week])
VAR _MaxWeek = MAX('Calendar'[Week])

RETURN
CALCULATE( DISTINCTCOUNT('Calendar'[Year_Week]), 
FILTER(ALL('Calendar'), 
    'Calendar'[Date].[Year] >= _MinYear && 'Calendar'[Date].[Year] <= _MaxYear &&
    'Calendar'[Month] >= _MinMonth && 'Calendar'[Month] <= _MaxMonth &&
    'Calendar'[Week] >= _MinWeek && 'Calendar'[Week] <= _MaxWeek))

 

isjoycewang_0-1702289278232.png

 

Best Regards,

Joyce

View solution in original post

4 REPLIES 4
isjoycewang
Super User
Super User

Provide demo file and another DAX for reference:

 

WkCount = 
VAR _MinYear = MIN('Calendar'[Date].[Year])
VAR _MaxYear = MAX('Calendar'[Date].[Year])
VAR _MinMonth = MIN('Calendar'[Month])
VAR _MaxMonth = MAX('Calendar'[Month])
VAR _MinWeek = MIN('Calendar'[Week])
VAR _MaxWeek = MAX('Calendar'[Week])

RETURN
CALCULATE( DISTINCTCOUNT('Calendar'[Year_Week]), 
FILTER(ALL('Calendar'), 
    'Calendar'[Date].[Year] >= _MinYear && 'Calendar'[Date].[Year] <= _MaxYear &&
    'Calendar'[Month] >= _MinMonth && 'Calendar'[Month] <= _MaxMonth &&
    'Calendar'[Week] >= _MinWeek && 'Calendar'[Week] <= _MaxWeek))

 

isjoycewang_0-1702289278232.png

 

Best Regards,

Joyce

Hi @isjoycewang 

 

It works 🙂 Thank you!

 

devesh_gupta
Super User
Super User

@A_a_a Convert your Year slicer also as range kind of slicer similar to Month & Week slicers and then use this DAX, it might help:

TotalSelectedWeeks = 
VAR MinSelectedYear = MIN('Date'[Year])
VAR MaxSelectedYear = MAX('Date'[Year])
VAR MinSelectedMonth = MIN('Date'[Month])
VAR MaxSelectedMonth = MAX('Date'[Month])
VAR MinSelectedWeek = MIN('Date'[Week])
VAR MaxSelectedWeek = MAX('Date'[Week])

RETURN
CALCULATE(
    COUNTROWS('Date'),
    ('Date'[Year] >= MinSelectedYear || ISBLANK(MinSelectedYear)) && ('Date'[Year] <= MaxSelectedYear || ISBLANK(MaxSelectedYear)),
    ('Date'[Month] >= MinSelectedMonth || ISBLANK(MinSelectedMonth)) && ('Date'[Month] <= MaxSelectedMonth || ISBLANK(MaxSelectedMonth)),
    ('Date'[Week] >= MinSelectedWeek || ISBLANK(MinSelectedWeek)) && ('Date'[Week] <= MaxSelectedWeek || ISBLANK(MaxSelectedWeek))
)

 

If you find this insightful, please provide a Kudo and accept this as a solution.

Hi @devesh_gupta 

 

Thank you for your message.

Not sure why, the number of weeks is incorrect.

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! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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