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
BlackBird
Helper I
Helper I

Count of last update per day

I am working on a covid-19 report of suspected and confirmed cases for my company contracts, and I need to count the amount of cases for each day, based on LastUpdate.

 

My dataset looks like this

 

LastUpdateContractEmployeeNameSuspectedConfirmed
01/04/2020AEmployeeANoNo
01/04/2020AEmployeeBNoNo
01/04/2020AEmployeeCNoNo
01/04/2020BEmployeeDYesNo
01/04/2020BEmployeeENoNo
01/04/2020CEmployeeFNoNo
01/04/2020CEmployeeGNoNo
01/04/2020CEmployeeHYesNo
02/04/2020AEmployeeANoNo
02/04/2020AEmployeeBYesNo
02/04/2020AEmployeeCNoNo
02/04/2020BEmployeeDYesNo
02/04/2020BEmployeeENoNo
03/04/2020AEmployeeANoNo
03/04/2020AEmployeeBYesNo
03/04/2020AEmployeeCNoNo
03/04/2020BEmployeeDYesNo
03/04/2020BEmployeeENoNo
03/04/2020CEmployeeFNoNo
03/04/2020CEmployeeGNoNo
03/04/2020CEmployeeHNoYes
04/04/2020BEmployeeDYesNo
04/04/2020BEmployeeENoNo
04/04/2020CEmployeeFNoNo
04/04/2020CEmployeeGNoNo
04/04/2020CEmployeeHNoYes

 

and I'm trying to output this

 

DateSuspectedConfirmed
01/04/202020
02/04/202030
03/04/202021
04/04/202021

 

Not all contracts report everyday, in this case I need to count the last date it has updated.

Like above where on 02/04, contracts A and B reported 2 suspected cases + contract C update from 01/04 with 1 suspected case.

 

I don't now how to aproach this, can you help me?

4 REPLIES 4
Greg_Deckler
Super User
Super User

OK, this one was tricky, but I believe I have it, see attached PBIX, the basic pattern is:

 

Suspected Measure = 
    VAR __Date = MAX('Table'[LastUpdate])
    VAR __Table =
        ADDCOLUMNS(
            SUMMARIZE(
                FILTER(ALL('Table'),[LastUpdate]<=__Date),
                [Contract],
                "LastDate",MAX('Table'[LastUpdate])
            ),
            "Suspected",COUNTROWS(FILTER(ALL('Table'),'Table'[Contract]=EARLIER([Contract]) && [LastUpdate] = [LastDate] && [Suspected]="Yes"))
        )
RETURN
    SUMX(FILTER(__Table,[LastDate] <= __Date),[Suspected])


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Thanks Greg it worked perfectly! 

 

But it didn't work with filters the way I thought... and I guess I should have mentioned it on the post, I'm sorry.

I have a separated table with all Contracts, with a Management column wich I use on a slicer.

 

Like this:

ContractManagement
AM1
BM1
CM2

 

When I use the slicer, instead of calculating the number of suspected/confirmed cases of that management, it is showing the whole number for the days in wich the contracts of that management have updated.

 

How do I change it?

Icey
Community Support
Community Support

Hi @BlackBird ,

 

Replace ALL() with ALLSELECTED() in the measures.

Suspected Measure = 
VAR __Date =
    MAX ( 'Table'[LastUpdate] )
VAR __Table =
    ADDCOLUMNS (
        SUMMARIZE (
            FILTER ( ALLSELECTED ( 'Table' ), [LastUpdate] <= __Date ), ------changed
            [Contract],
            "LastDate", MAX ( 'Table'[LastUpdate] )
        ),
        "Suspected", COUNTROWS (
            FILTER (
                ALLSELECTED ( 'Table' ),                         --------------changed
                'Table'[Contract] = EARLIER ( [Contract] )
                    && [LastUpdate] = [LastDate]
                    && [Suspected] = "Yes"
            )
        )
    )
RETURN
    SUMX ( FILTER ( __Table, [LastDate] <= __Date ), [Suspected] ) + 0
Confirmed Measure =
VAR __Date =
    MAX ( 'Table'[LastUpdate] )
VAR __Table =
    ADDCOLUMNS (
        SUMMARIZE (
            FILTER ( ALLSELECTED ( 'Table' ), [LastUpdate] <= __Date ), --------changed
            [Contract],
            "LastDate", MAX ( 'Table'[LastUpdate] )
        ),
        "Confirmed", COUNTROWS (
            FILTER (
                ALLSELECTED ( 'Table' ),        --------------------------------changed
                'Table'[Contract] = EARLIER ( [Contract] )
                    && [LastUpdate] = [LastDate]
                    && [Confirmed] = "Yes"
            )
        )
    )
RETURN
    SUMX ( FILTER ( __Table, [LastDate] <= __Date ), [Confirmed] ) + 0

sus.gif

 

Best Regards,

Icey

 

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

I'll have to take a look, it was complex enough that it took a good half hour to work through it so I'll have to add that to the model and see what needs to be done.


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

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!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

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.