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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Yaseen_Nadaf
Regular Visitor

Need Help to use unique values of a measure as a row value then count unique id against that row

I have a raw table name as Query1 which contains logs of call status for multiple students.  It has 4 columns student_id, enquire_date, call_status, date_added. One student_id has only 1 enquire_date but it may have many different date_added and call_status.

i have to create a visual where 2 slicer options needs to be given one for enquire_date one for disposition_date. Dispostion date is basically the date for which we need to check the latest availaible call_status of student_id.

for eg if i select enquire_date as 1 Oct 2024 then and dispostion_date as 3 Oct 2024, the table should show the latest availaible call status for 1 Oct 2024 enquired students whose latest date_added can be 3 Oct 2024 or before.
Data Tables:

Yaseen_Nadaf_0-1734077556746.png

CalenderTable is a calculated table which i have created which just has calender dates and it is not in relationship with Query1. Date from Calender Table I will be using as Disposition Date.
Call Status for Latest Date and Latest Availaible Date Added are the two dynamic measures which I have created which are using 2 slicers as input.


Measure 1 Calculation:

Call Status for Latest Date =
CALCULATE(
    MAX(Query1[call_status]),
    FILTER(
        Query1,
        Query1[date_added] =
        CALCULATE(
            MAX(Query1[date_added]),
            FILTER(
                Query1,
                Query1[date_added] <= SELECTEDVALUE(CalendarTable[Date]) &&
                NOT(ISBLANK(Query1[call_status])) -- Exclude rows where call_status is null
            )
        ) &&
        NOT(ISBLANK(Query1[call_status])) -- Ensure call_status is non-null in the outer filter
    )
)




Measure 2 Calculation:

Latest Available Date Added =
CALCULATE(
    MAX(Query1[date_added]),
    FILTER(
        Query1,
        Query1[date_added] <= SELECTEDVALUE(CalendarTable[Date]) && -- Compare dates
        NOT(ISBLANK(Query1[call_status])) -- Exclude rows where call_status is null
    )
)

This is the output and table is showing correct data:

Yaseen_Nadaf_1-1734078067431.png

I have to export this table as excel and then apply a pivot to check the call status and unique student count aggregated.

Yaseen_Nadaf_2-1734078296497.png

I need a way to create same visual in power BI without exporting it in excel but unable to do it as I cannot use measures as a row.

 

1 ACCEPTED SOLUTION

Hi @Yaseen_Nadaf 

These are the measures I've come up with

Latest Date = 
VAR DispositionDate =
    MAX ( CalendarTable[Date] )
RETURN
    CALCULATE (
        MAX ( Query1[date_added] ),
        ALLEXCEPT ( Query1, Query1[student_id] ),
        KEEPFILTERS ( INT ( Query1[date_added] ) <= DispositionDate )
    )


Count by Status = 
VAR _latestdate = [Latest Date]
RETURN
    COUNTROWS (
        FILTER (
            ADDCOLUMNS (
                SUMMARIZE (
                    Query1,
                    Query1[student_id],
                    Query1[call_status],
                    Query1[date_added]
                ),
                "@latest date", [Latest Date]
            ),
            [@latest date] = [date_added]
        )
    )

Please note that i wrapped date_added with INT as it is a date_time and you're comparing it against a date so essentially, with your current logic, <= will exclude anything beyond 12:00 AM

 

How do you handle these duplicate records?

danextian_1-1734094000173.png

danextian_2-1734094056497.png

 

 

Count by status measure counts onlyn once.










Did I answer your question? Mark my post as a solution!


Proud to be a Super User!









"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

View solution in original post

7 REPLIES 7
danextian
Super User
Super User

Hi @Yaseen_Nadaf 

 

Can you please post a workable sample data (not an image) and your expected result from that.










Did I answer your question? Mark my post as a solution!


Proud to be a Super User!









"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

Hi @Yaseen_Nadaf 

These are the measures I've come up with

Latest Date = 
VAR DispositionDate =
    MAX ( CalendarTable[Date] )
RETURN
    CALCULATE (
        MAX ( Query1[date_added] ),
        ALLEXCEPT ( Query1, Query1[student_id] ),
        KEEPFILTERS ( INT ( Query1[date_added] ) <= DispositionDate )
    )


Count by Status = 
VAR _latestdate = [Latest Date]
RETURN
    COUNTROWS (
        FILTER (
            ADDCOLUMNS (
                SUMMARIZE (
                    Query1,
                    Query1[student_id],
                    Query1[call_status],
                    Query1[date_added]
                ),
                "@latest date", [Latest Date]
            ),
            [@latest date] = [date_added]
        )
    )

Please note that i wrapped date_added with INT as it is a date_time and you're comparing it against a date so essentially, with your current logic, <= will exclude anything beyond 12:00 AM

 

How do you handle these duplicate records?

danextian_1-1734094000173.png

danextian_2-1734094056497.png

 

 

Count by status measure counts onlyn once.










Did I answer your question? Mark my post as a solution!


Proud to be a Super User!









"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

Thanks a lot man @danextian. This worked perfectly fine. I removed the duplicate rows and null call status values from source itself.
and for a unique date added i considered only one latest row as per time for that day.

Yaseen_Nadaf_0-1734108074583.png

 

Able to get the desired output in same view as expected. Thanks a lot. Was not able to solve this problem since months even after using Chat GPT. 

You are genius!!

Yaseen_Nadaf
Regular Visitor

Can you suggest any way please?

 @Jai-Rathinavel @danextian @Bibiano_Geraldo @rajendraongole1 

Hi @Yaseen_Nadaf ,

Can you please share a sample pbi file with no sensitive data? please.

I hope this helps! 
If you found this answer helpful:
✔️ Mark it as the solution to help others find it faster.
 Give it a like to show your appreciation!

Thank you for contributing to our amazing Power BI community! 

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!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.