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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
sivarajan21
Post Prodigy
Post Prodigy

KPI dax logic not giving correct counts but table visual does

Hi Team,

 

I have below dax for the Doors open kpi:

Doors Open = VAR _count =
    CALCULATE( MAX( BMSDoorStoreJoin[CreatedOn] ), BMSDoorStoreJoin[Status] = "Open" )
VAR _siteid = MAX(BMSDoorStoreJoin[SiteId])
RETURN
    CALCULATE(
        COUNT( BMSDoorStoreJoin[CreatedOn] ),
        BMSDoorStoreJoin[Status] = "Open"&&
        BMSDoorStoreJoin[CreatedOn] = _count &&
        BMSDoorStoreJoin[SiteId] = _siteid 
        
    )

 

Now, this returns the value of 1 which is wrong according to filtered SiteId(StoreName). 
My expected output from this logic is I want to find unique count of Doors Open(Site[Sitecode]) for the max of createdon date. For example, the data below for Sitecode 472

sivarajan21_0-1741197906460.png

we have Status as closed and we don't have open. So it should retun nil. but in this case it returns 1. 

My table visual also shows correctly that it has only closed status. When i use my kpi logic in that visual it gives correct count. 

sivarajan21_1-1741198097951.png

Please advise!

PFA file here BMS Chillers Insights.pbix

 

@marcorusso @Ahmedx @danextian @Anonymous @tharunkumarRTK 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi, @sivarajan21 

I can't open your file connection.

vjianpengmsft_0-1741248392830.png

Maybe you can try this expression:

Doors Open = 
VAR StatusFiltered =
FILTER(
    SUMMARIZE(
        BMSDoorStoreJoin,
        BMSDoorStoreJoin[SiteId],
        "MaxDateOpen", 
        CALCULATE(
            MAX(BMSDoorStoreJoin[CreatedOn]),
            BMSDoorStoreJoin[Status] = "Open"
        )
    ),
    NOT ISBLANK([MaxDateOpen])
)
VAR ActiveSites = 
TOPN(
    1,
    ADDCOLUMNS(
        StatusFiltered,
        "HasValidEntry",
        CALCULATE(
            COUNTROWS(BMSDoorStoreJoin),
            BMSDoorStoreJoin[CreatedOn] = [MaxDateOpen],
            BMSDoorStoreJoin[Status] = "Open"
        ) > 0
    ),
    -1,
    [MaxDateOpen]
)
RETURN
COUNTROWS(FILTER(ActiveSites, [HasValidEntry]))

 

 

Best Regards

Jianpeng Li

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

 

 

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi, @sivarajan21 

I can't open your file connection.

vjianpengmsft_0-1741248392830.png

Maybe you can try this expression:

Doors Open = 
VAR StatusFiltered =
FILTER(
    SUMMARIZE(
        BMSDoorStoreJoin,
        BMSDoorStoreJoin[SiteId],
        "MaxDateOpen", 
        CALCULATE(
            MAX(BMSDoorStoreJoin[CreatedOn]),
            BMSDoorStoreJoin[Status] = "Open"
        )
    ),
    NOT ISBLANK([MaxDateOpen])
)
VAR ActiveSites = 
TOPN(
    1,
    ADDCOLUMNS(
        StatusFiltered,
        "HasValidEntry",
        CALCULATE(
            COUNTROWS(BMSDoorStoreJoin),
            BMSDoorStoreJoin[CreatedOn] = [MaxDateOpen],
            BMSDoorStoreJoin[Status] = "Open"
        ) > 0
    ),
    -1,
    [MaxDateOpen]
)
RETURN
COUNTROWS(FILTER(ActiveSites, [HasValidEntry]))

 

 

Best Regards

Jianpeng Li

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

 

 

Hi @Anonymous sir,

 

thanks for your quick response!

its resolved now

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.