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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
BlackBird
Frequent Visitor

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])

@ 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!:
The Definitive Guide to Power Query (M)

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.

@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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