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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
farhanerd
Frequent Visitor

Calculate Daily Differences Based on Dates and Changing Province

Hello, I need to make a line graph actually like this picture below, but with a different table

Screenshot_497.png

It is quite actually simple on making that graph since id_provinsi is not changing and I am still able to get the difference between each row on each column

Screenshot_499.png

I need the solution if id_provinsi is changing daily in ascending way based on the earliest date like this picture below:
Screenshot_502.png

idid_provinsiterkonfirmasisembuhmeninggaltanggal
182641300772273513208/24/2021
1522003/15/2020


Thank you!
Farhan 🙂

5 REPLIES 5
v-xiaotang
Community Support
Community Support

Hi @farhanerd 

sorry for the late reply, try this

DiffKonfirmasi = 
VAR Konfirmasi_PreviousDate =
    MAXX (
        FILTER (
            'EWS covid_date_clean',
            'EWS covid_date_clean'[id_provinsi]
                = EARLIER ( 'EWS covid_date_clean'[id_provinsi] )
                && 'EWS covid_date_clean'[tanggal] < EARLIER ( 'EWS covid_date_clean'[tanggal] )
        ),
        'EWS covid_date_clean'[tanggal]
    )
VAR Konfirmasi_Previous =
    MAXX (
        FILTER (
            'EWS covid_date_clean',
            'EWS covid_date_clean'[tanggal] = Konfirmasi_PreviousDate
                && 'EWS covid_date_clean'[id_provinsi]
                    = EARLIER ( 'EWS covid_date_clean'[id_provinsi] )
        ),
        'EWS covid_date_clean'[Sembuh]
    )
RETURN
    'EWS covid_date_clean'[Sembuh] - Konfirmasi_Previous

vxiaotang_0-1633598635077.png

 

 

Best Regards,

Community Support Team _Tang

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

Greg_Deckler
Super User
Super User

@farhanerd See my article on Mean Time Between Failure (MTBF) which uses EARLIER: http://community.powerbi.com/t5/Community-Blog/Mean-Time-Between-Failure-MTBF-and-Power-BI/ba-p/3395....
The basic pattern is:
Column = 
  VAR __Current = [Value]
  VAR __PreviousDate = MAXX(FILTER('Table','Table'[Date] < EARLIER('Table'[Date])),[Date])

  VAR __Previous = MAXX(FILTER('Table',[Date]=__PreviousDate),[Value])
RETURN
  __Current - __Previous


@ 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...

This is my expected resultScreenshot_504.png

Hi @Greg_Deckler, I tried to put that query on my table but the result seems doesn't as what I expected.

farhanerd_0-1630566109901.png

Screenshot_503.png

Am I put the query wrong?
I'm kinda new here and after lots and lots of trying attempts I still didn't get the answer I want, I need your guidance @Greg_Deckler 

@farhanerd I am guessing that there is some kind of identifier that identifies which rows are "grouped" together. For example, I see a bunch of March 16th rows in your data. Thus, I am guessing that there are probably multiple March 15th rows. The code you have will find March 15th for the Previous Date. But, it will then look up the largest value on that date, which is apparently 210. So, if  you were looking for 117 instead I think you will need to add more specificity to your FILTER statemetns like && [somecolumn] = EARLIER([somecolumn)

 

Note that you can also use VAR statements to grab your current values instead of using EARLIER.


@ 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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.