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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
sivarajan21
Post Prodigy
Post Prodigy

Dax logic for KPI not giving correct count but table visual dax gives correct count

Hi Team,

 

I have a dax measure created for this KPI card.

sivarajan21_0-1740805621895.png

 

Dax for KPI card :

Breach Total = 
CALCULATE(COUNTROWS(
    FILTER(
        Breachopenmin,
        VAR _createdon = CALCULATE(
        MAX(Breachopenmin[CreatedOn]),
        ALL(Breachopenmin))
        VAR _devid = Breachopenmin[DeviceId]
        VAR _status = Breachopenmin[DoorStatus]
        VAR _Sstatus = Breachopenmin[StoreStatus]
        VAR _openBMinutes = Breachopenmin[OpenBreachMinutes]
        RETURN
        (_Sstatus = "C" && _openBMinutes > 0) ||
        (_openBMinutes > 0 && _status = "Closed") ||
        (_openBMinutes > 0 && max(Breachopenmin[CreatedOn]) = _createdon && Breachopenmin[DeviceId] = _devid)
    )
))

 

But its giving wrong count here 19 instead of 1.

sivarajan21_1-1740805776085.png

 

Reason I am saying one here is look at the table visual and its dax to count the breach and its working correctly.

sivarajan21_2-1740805801122.png

 

Dax for table visual:

Breach = 
VAR _createdon = 
    CALCULATE(
        MAX(Breachopenmin[CreatedOn]),
        ALLEXCEPT(Breachopenmin, Breachopenmin[DeviceId])
    )
VAR _devid = SELECTEDVALUE(Breachopenmin[DeviceId])
VAR _status = SELECTEDVALUE(Breachopenmin[DoorStatus])
VAR _Sstatus = SELECTEDVALUE(Breachopenmin[StoreStatus])
VAR _openBMinutes = SELECTEDVALUE(Breachopenmin[OpenBreachMinutes])

RETURN
IF(
    (_Sstatus = "C" && _openBMinutes > 0) ||
    (_openBMinutes > 0 && _status="Closed") ||
     (_openBMinutes > 0 && MAX(Breachopenmin[CreatedOn]) = _createdon && _devid = _devid),
    1,
    BLANK()
)

 

My expected count here is 1. I don't think the KPI card visual needs to be this complex as we already have table visual breach working and just few things that needs change but am missing out.

KPI logic should count only the one instance that the max row and not all rows in table.
PFA file here BMS Door Insights.pbix

 

Please could you help to resolve kpi card count whenever you are free

Please let me know if you have any issues.

 

Many thanks in advance!

@tharunkumarRTK @marcorusso @Anonymous @Greg_Deckler @ray_aramburo 

1 ACCEPTED SOLUTION
danextian
Super User
Super User

Hi @sivarajan21 

 

Breach, Warnings and _SiteName measures are evaluated for each row in your table viz but no such evaluation happens when you use the KPI viz. SELECTEDVALUE also returns blank by default if not  a single value is selected. If you want those measures evaluated virtually, you can create a virtual table instead inside a measure and filter it.

 

Breach3 = 
SUMX (
    FILTER (
        KEEPFILTERS (
            SUMMARIZECOLUMNS (
                'Door'[SiteId],
                'Door'[CreatedOn],
                'Door'[Status],
                'OpenstateDuration'[OpenMinutes],
                'Store Status'[Status],
                "@SiteName", [_SiteName],
                "@Warnings", [Warnings],
                "@Breach", [Breach]
            )
        ),
        AND ( CONTAINSSTRING ( [@Warnings], "Yes" ), NOT ( ISBLANK ( [@SiteName] ) ) )
    ),
    [@Breach]
)

danextian_0-1740819946955.png

 

 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

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


"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

2 REPLIES 2
danextian
Super User
Super User

Hi @sivarajan21 

 

Breach, Warnings and _SiteName measures are evaluated for each row in your table viz but no such evaluation happens when you use the KPI viz. SELECTEDVALUE also returns blank by default if not  a single value is selected. If you want those measures evaluated virtually, you can create a virtual table instead inside a measure and filter it.

 

Breach3 = 
SUMX (
    FILTER (
        KEEPFILTERS (
            SUMMARIZECOLUMNS (
                'Door'[SiteId],
                'Door'[CreatedOn],
                'Door'[Status],
                'OpenstateDuration'[OpenMinutes],
                'Store Status'[Status],
                "@SiteName", [_SiteName],
                "@Warnings", [Warnings],
                "@Breach", [Breach]
            )
        ),
        AND ( CONTAINSSTRING ( [@Warnings], "Yes" ), NOT ( ISBLANK ( [@SiteName] ) ) )
    ),
    [@Breach]
)

danextian_0-1740819946955.png

 

 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

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


"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 @danextian ,

 

Thanks for your quick response!

It made my day and it means a lot. Your service to community is invaluable. 

Keep up the good work! please let me know if you need my help. For example, i am on linkedin, if you want to endore your blogs/work etc. 😊

 

You saved me from hours of frustration!

i will close this query

 

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 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
Top Kudoed Authors