Forum Discussion
Power Bi -> Max_value and Count
Hi
The table is filtered by the Date column.
first question: i am trying to output the maximum date in one column and the minimum date in a second column. Both should come from the date column. so min_Date needs to be 18.12.2024 and max_Date needs to be 26.02.2025. Unfortunately this does not work so far
second question: In the filtered table I want to count the number of dates for each ID.
In Tableau I managed to do this using the FIXED function, in Power Bi I'm a bit desperate and can't get it to work. So for ID 134 count is one (same for ID 141), for ID 164 it needs to be 2 on both rows.
Does anyone knows how to do this? And thanks in advance.
Hi Molika,
I understand your requirement.
Please find the updated DAX measure below:DateCountPerID_Filtered =
CALCULATE(
COUNTROWS('Table'),
FILTER(
'Table',
'Table'[ID] = MAX('Table'[ID])
)
)
Please refer below attached snaps for your reference.
I hope my suggestions provided valuable insights. If you have any further questions, don’t hesitate to ask in a follow-up message.
If this post helped, please mark it as "Accept as Solution" so others can benefit as well.Best regards,
Sahasra.
9 Replies
- rajendraongole1Super User
Hi Molika - Create These Two Measures as follows:
Min_Date_Filtered = MIN('YourTable'[Date])
Max_Date_Filtered = MAX('YourTable'[Date])You want to count how many times each id appears in the filtered table
Count_Dates_Per_ID =
CALCULATE(
COUNTROWS('YourTable'),
ALLEXCEPT('YourTable', 'YourTable'[id])
)It respect the slicer (filtered Date column)
Return 1 for ID 134 and 141
Return 2 for ID 164 (as it appears with two different dates)
Hope this helps, pelase check.
- MolikaRegular Visitor
Hi, thanks for your response.
for ID 164 it counts 3 because it also appearse in the data with date 26.01.2025. although this date is not selected in the filter. As long as i have the columns 'date' in my view MIN / MAX just works for each row. when deleting the Column it works, but i need it within the View 😕
- v-sgandrathiCommunity Support
Hi Molika,
Thanks for using Microsoft Fabric Community Forum.
To ensure that the minimum and maximum date values calculate correctly even when the Date column is present in the visual, you must use DAX measures that remove the row context introduced by the Date column while still respecting the applied filters or slicers.
To fix the issue where the count includes dates not selected in the filter (e.g., 26.01.2025), you need to write the measure in a way that:
Groups by ID using ALLEXCEPT
Preserves filter context from slicers or visuals using KEEPFILTERS or similar
This approach ensures Min_Date and Max_Date return consistent values for all rows, regardless of Date being in the table. And the Count for each ID includes only the dates currently selected (e.g., 2 for ID 164, excluding 26.01.2025).
I hope my suggestions provided valuable insights. If you have any further questions, don’t hesitate to ask in a follow-up message.
If this post helped, please mark it as "Accept as Solution" so others can benefit as well.Best regards,
Sahasra.- MolikaRegular Visitor
Hi,
i used the solution from rejendaongole1 but do not understand how to preserves filter context from slicers by using KEEPFILTERS. SO at the moment i got 3 for ID 164.
Count_Dates_Per_ID =
CALCULATE(
COUNTROWS('YourTable'),
ALLEXCEPT('YourTable', 'YourTable'[id])
)
- v-sgandrathiCommunity Support
Hi Molika,
Please follow below steps.
1. I have created sample table(Table) and columns (ID and Date).
2. Created MIN and MAX Measures with below DAX.Min_Date = MIN('Table'[Date])
Max_Date = MAX('Table'[Date])3. Count of Dates per ID's :
Created below measure for Date count per ID.
DateCountPerID =
CALCULATE(
COUNTROWS('Table'),
ALLEXCEPT('Table', 'Table'[ID])
)4. In Table visual, drag all the columns and drag Date column to slicer.
Please refer below attached snaps for your reference.
Please follow below steps.
1. I have created sample table(Table) and columns (ID and Date).
2. Created MIN and MAX Measures with below DAX.Min_Date = MIN('Table'[Date])
Max_Date = MAX('Table'[Date])3. Count of Dates per ID's :
Created below measure for Date count per ID.
DateCountPerID =
CALCULATE(
COUNTROWS('Table'),
ALLEXCEPT('Table', 'Table'[ID])
)4. In Table visual, drag all the columns and drag Date column to slicer.
Please refer below attached snaps for your reference.
If this solution worked for you, kindly mark it as Accept as Solution and feel free to give a Kudos, it would be much appreciated!
Thank you.
- MolikaRegular Visitor
Hi and thanks for your response.
that is what i already have as rsult BUT i expect that ID164 is counted with 1 and not 2 because i have not selected 02/01/2025 wthin the slicer. I hope you can understand what I mean.
Best regards
- v-sgandrathiCommunity Support
Hi Molika,
I understand your requirement.
Please find the updated DAX measure below:DateCountPerID_Filtered =
CALCULATE(
COUNTROWS('Table'),
FILTER(
'Table',
'Table'[ID] = MAX('Table'[ID])
)
)
Please refer below attached snaps for your reference.
I hope my suggestions provided valuable insights. If you have any further questions, don’t hesitate to ask in a follow-up message.
If this post helped, please mark it as "Accept as Solution" so others can benefit as well.Best regards,
Sahasra.