0
votes

I just want to select a range of days in a slicer and show in a table the number of days for each month/period (month-year).

I used DAX to create a table with the information I need and I don't have problems with the periods (first column), it changes dinamically, the problem is the column "Days" (second column) because it's always showing the total number of days for each month.

Here my DAX code

SelectedPeriods = GROUPBY(DimDate;DimDate[Period];"Days";COUNTX(CURRENTGROUP();DimDate[DateKey]))

Here the result

What I expect is:

2 for april, 31 for may, 1 for june

1
Is SelectedPeriods a measure or a calculated table?BarneyL
It's a calculated tableHeberWalter

1 Answers

1
votes

This is an issue with execution order.

SelectedPeriods = GROUPBY(DimDate;DimDate[Period];"Days";COUNTX(CURRENTGROUP();DimDate[DateKey]))

Generates a calculated table. These are calculated when the data model is refreshed and stored in it. They are not refreshed each time a connected dimension is changed within a dashboard.

In your case, while changing date filters may hide rows from this table the number of days remains fixed at the number calculated initially when there was no filter context on the data i.e. counting all days in the month.

If you want the result to change then you need to use a measure instead of a calculated table. Measures react to the current filter context within the report and so will adjust their output each time a slicer is changed. The needed measure will depend on your model but might be something as simple as:

CountOfDays := CountRows(DimDate)