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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
awg201
Frequent Visitor

Measure not returning the LATEST value in category

Hi, I have written a measure which aims to count the number of cases that were open as at a selected period (financial year starting JULY) from a slicer. It counts correct when used by itself, but when I add the location column in, it seems to double up numbers if a case has multiple locations in the same period.

 

Below is a very small example data:

CaseIDCaseStartDateCaseEndDateFinaliseDateLocationName
A17-Dec-2419-Dec-24 SYDNEY
A11-Sep-2411-Sep-24 SYDNEY
A11-Feb-2513-Feb-25 MELBOURNE
A26-Apr-2426-Apr-24 SYDNEY

 

Here is the DAX measure i have written:

Count_OpenCases = 
VAR MaxDate = MAX('DateTable'[Date])

-- aggregated case dates in period
VAR CaseSummary =
    ADDCOLUMNS(
        SUMMARIZE(
            CasesTable,
            CasesTable[CaseID]
        ),
        "EarliestCaseDate", CALCULATE(MIN(CasesTable[CaseStartDate])),
        "LatestFindingsDate", CALCULATE(MAX(CasesTable[FindingsDate])),
        "LastLocation", 
            CALCULATE(
                SELECTCOLUMNS(
                    TOPN(1, 
                        FILTER(
                            CasesTable, 
                            CasesTable[CaseStartDate] <= MaxDate
                        ), 
                        CasesTable[CaseStartDate], DESC
                    ),
                    "Location", CasesTable[LocationName]
                )
            )
    )

-- get cases still open as at selected period
VAR OpenCases =
    FILTER(
        CaseSummary,
        [EarliestCaseDate] <= MaxDate &&
        (
            ISBLANK([LatestFindingsDate]) || [LatestFindingsDate] > MaxDate
        )
    )

RETURN COUNTROWS(OpenCases)

When i slice for 2025, it returns 1, which is correct, but in a table visual (or charts), i get:

LocationNameCount_OpenCases CaseID
MELBOURNE1A
SYDNEY1A
TOTAL1 

I have a rough understanding of why this is showing, as technically , they are both present in FY2025 (Jul 24 to Jun25), but I want  it to only show Melbourne as this is the latest location based on the CaseStartDate.

 

When run the CaseSummary in DAX query view, the table produced seem to get the correct results with my input year, with the locations dynamically updated.

 

How can get this in a visual:

LocationNameCount_OpenCases CaseID
MELBOURNE1A

Please help!

1 ACCEPTED SOLUTION

Hi @awg201,

Please refer the below atached .PBIX file.

 

If this post helps, then please give us ‘Kudos’ and consider Accept it as a solution to help the other members find it more quickly.

 

Thank you.

View solution in original post

10 REPLIES 10
bhanu_gautam
Super User
Super User

@awg201 , Try using

dax
Count_OpenCases =
VAR MaxDate = MAX('DateTable'[Date])

-- aggregated case dates in period
VAR CaseSummary =
ADDCOLUMNS(
SUMMARIZE(
CasesTable,
CasesTable[CaseID]
),
"EarliestCaseDate", CALCULATE(MIN(CasesTable[CaseStartDate])),
"LatestFindingsDate", CALCULATE(MAX(CasesTable[FindingsDate])),
"LastLocation",
CALCULATE(
SELECTCOLUMNS(
TOPN(1,
FILTER(
CasesTable,
CasesTable[CaseStartDate] <= MaxDate
),
CasesTable[CaseStartDate], DESC
),
"Location", CasesTable[LocationName]
)
)
)

-- get cases still open as at selected period
VAR OpenCases =
FILTER(
CaseSummary,
[EarliestCaseDate] <= MaxDate &&
(
ISBLANK([LatestFindingsDate]) || [LatestFindingsDate] > MaxDate
)
)

-- get the latest location for each case
VAR LatestLocationCases =
ADDCOLUMNS(
OpenCases,
"LatestLocation", [LastLocation]
)

RETURN
COUNTROWS(
FILTER(
LatestLocationCases,
LatestLocationCases[LastLocation] = MAX(CasesTable[LocationName])
)
)




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






That was a speedy response! Thanks for that

 

I had tried a similar variation, but i seem to get the similar error "Cannot find table 'LatestLocationCases'.". It just doesn't seem to let me reference any virtual tables created as variables.

Hi @awg201,

Thank you for reaching you ti the Microsoft Forum Community.

 

I have created a measure that uses ranking based on CaseEndDate. You can adjust the ranking logic to suit your specific requirements and apply the necessary filtering as shown below

vsaisraomsft_0-1744095683487.png

Attached the Pbix file for your reference.

If you need help please share the additional data to provide exact solution.

 

Hi @v-saisrao-msft , thanks for your help

 

For some reason, when I apply this to a larger dataset, it just returns a single row with an unexpected result.

 

So I tried it in your example by adding more data, and got the same outcome:

awg201_2-1744251039866.png

 

Here is the expanded DATASET:

CaseIDCaseStartDateCaseEndDateLocationName
A17-Dec-2419-Dec-24SYDNEY
A11-Sep-2411-Sep-24HOBART
A11-Feb-2513-Feb-25MELBOURNE
A26-Apr-2426-Apr-24SYDNEY
B01-Jan-2406-Jan-24BRISBANE
B03-Jun-2308-Jun-23SINGAPORE
C12-Feb-2416-Feb-24TEXAS
C15-Mar-2418-Mar-24NEW YORK
D22-Jul-2425-Jul-24LONDON
D05-Nov-2407-Nov-24PARIS
E10-Aug-2412-Aug-24TOKYO
E19-Sep-2421-Sep-24BERLIN
F02-Oct-2405-Oct-24SYDNEY
F14-Dec-2416-Dec-24MELBOURNE
G23-Jan-2525-Jan-25BRISBANE
G08-Apr-2510-Apr-25SINGAPORE
G23-Jun-2525-Jun-25NEW ZEALAND
H17-May-2519-May-25TEXAS

 

Below would be the desired result:

Sliced for 2024

CaseIDCaseStartDateCaseEndDateLocationName
A17-Dec-2419-Dec-24SYDNEY
B01-Jan-2406-Jan-24BRISBANE
C15-Mar-2418-Mar-24NEW YORK
D05-Nov-2407-Nov-24PARIS
E19-Sep-2421-Sep-24BERLIN
F14-Dec-2416-Dec-24MELBOURNE


for 2025:

CaseIDCaseStartDateCaseEndDateLocationName
A11-Feb-2513-Feb-25MELBOURNE
G23-Jun-2525-Jun-25NEW ZEALAND
H17-May-2519-May-25TEXAS


it would proably need to be dynamic as we may need to drill down into months as well... thanks again for your help. I've spent way too long trying to ge this to work..

Hi @awg201,

May I ask if you have resolved this issue? If so, please mark the helpful reply and accept it as the solution. This will be helpful for other community members who have similar problems to solve it faster.

Thank you.

Hi @awg201,
I hope this information is helpful. Please let me know if you have any further questions or if you'd like to discuss this further. If this answers your question, please Accept it as a solution and give it a 'Kudos' so others can find it easily.
Thank you.

Hi @awg201,

Please refer the below attached .PBIX file

 

Thank you

@v-saisrao-msft thanks again. I think this would have to be a dynamic measure rather than a column. Essentialy, a case should only be counted once in a period, whether it be a month or a year.

 

I think what you had initally was close, but for some reason, it did not like it when a larger dataset was used.

 

CaseIDCaseStartDateCaseEndDateLocationName
A17-Dec-2419-Dec-24SYDNEY
A11-Sep-2411-Sep-24HOBART
A11-Feb-2513-Feb-25MELBOURNE
A26-Apr-2426-Apr-24SYDNEY
B01-Jan-2406-Jan-24BRISBANE
B03-Jun-2308-Jun-23SINGAPORE
C12-Feb-2416-Feb-24TEXAS
C15-Mar-2418-Mar-24NEW YORK
D22-Jul-2425-Jul-24LONDON
D05-Nov-2407-Nov-24PARIS
E10-Aug-2412-Aug-24TOKYO
E19-Sep-2421-Sep-24BERLIN
F02-Oct-2405-Oct-24SYDNEY
F14-Dec-2416-Dec-24MELBOURNE
G23-Jan-2525-Jan-25BRISBANE
G08-Apr-2510-Apr-25SINGAPORE
G23-Jun-2525-Jun-25NEW ZEALAND
H17-May-2519-May-25TEXAS

 

If we just focus on Case A, when I slice for 2024 for example, I should see:

CaseIDCaseStartDateCaseEndDateLocationName
A17-Dec-2419-Dec-24SYDNEY

 

but when i further filter or drill for the month Febraury in 2024, i should only get

CaseIDCaseStartDateCaseEndDateLocationName
A11-Feb-2513-Feb-25MELBOURNE

Hi @awg201,
I hope this information is helpful. Please let me know if you have any further questions or if you'd like to discuss this further. If this answers your question, please Accept it as a solution and give it a 'Kudos' so others can find it easily.
Thank you.

Hi @awg201,

Please refer the below atached .PBIX file.

 

If this post helps, then please give us ‘Kudos’ and consider Accept it as a solution to help the other members find it more quickly.

 

Thank you.

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors