Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.
I need help with calculating a dynamic column.
I want to calculate the frequency of a number within a date range selected by a slicer.
I'm currently using this to calculate the column and it works fine, but it calculates for the whole table. But it's not accurate because it should be calculating the frequency for the selected date range, not the entire table.
frequency =
COUNTX (
FILTER ( Table2, EARLIER ( Table2[number] ) = Table2[number] ),
Table2[number]
)
I have a slicer on the report for the date that charts the number frequency over time in the selected date range. The chart's not accurate because it's showing the frequency of the number in for all time, not the range selected.
I've been trying to figure out how to use FILTER and ALLSELECTED in the DAX formula, but I can't get it to work right and I'm not even sure if they're the right thing to use.
How can I change the "frequency" formula so that it calculates the frequency of "days" based on the date range selected by the slicer?
Here's example data for reference:
day | number | frequency |
1/1/22 | 78 | |
1/2/22 | 2 | |
1/2/22 | 78 | |
1/5/22 | 1 | |
1/8/22 | 2 |
Solved! Go to Solution.
Hi @Anonymous ,
You can create a measure. Both the following measures can work.
frequency = COUNTROWS(FILTER(ALLSELECTED('Table'),[number]=MAX('Table'[number])))
frequency2 = CALCULATE(COUNT('Table'[day]),FILTER(ALLSELECTED('Table'),[number]=MAX('Table'[number])))
Best Regards,
Stephen Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @Anonymous ,
You can create a measure. Both the following measures can work.
frequency = COUNTROWS(FILTER(ALLSELECTED('Table'),[number]=MAX('Table'[number])))
frequency2 = CALCULATE(COUNT('Table'[day]),FILTER(ALLSELECTED('Table'),[number]=MAX('Table'[number])))
Best Regards,
Stephen Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi,
Measures are often far simpler and more effective than Calculated Columns, not least since they respond to filtering.
MyFrequency :=
COUNTROWS( Table2 )
which can then be used in a visual alongside the activity_days field.
Regards
Thanks for the quick reply @Jos_Woolley
Unfortunately, I don't think that will work in my case because the frequency value is then charted over time so that we see trends of "day_frequency" for the date range selected in the slicer.
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
10 | |
8 | |
8 | |
8 | |
6 |
User | Count |
---|---|
14 | |
12 | |
11 | |
9 | |
9 |