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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
richardlynch
Frequent Visitor

Count the number of Ids with decreases in a time series

Hi,

 

I'm really stuck on this one so I appreciate any help.

Say I have a time series table called Charges where the Charges can vary over time for any person. I want a create measure to count the number of people with a decrease in charge between the first and last dates. This will need to be affected by a date slicer. 

 

PersonDateCharge
101/04/2022320
102/04/2022320
103/04/2022320
104/04/2022320
105/04/2022320
106/04/2022330
107/04/2022330
201/04/2022320
202/04/2022320
203/04/2022320
204/04/2022340
205/04/2022340
206/04/2022340
207/04/2022340
301/04/2022300
302/04/2022310
303/04/2022300
304/04/2022300
305/04/2022300
306/04/2022300
307/04/2022300
403/04/2022300
404/04/2022300
405/04/2022300
406/04/2022300
407/04/2022200
408/04/2022200


I tried this sort of thing, but it's returning blank. The expected output would be 1 for person 4 who goes from a charge of 300 to 200 on the last day.

 

 

 

 

Number of people with decreases = 
    var gp = FILTER(
                ADDCOLUMNS(
                    SUMMARIZECOLUMNS(
                        Charges[Person], 
                        "First rate", FIRSTNONBLANK(Charges[Charge], TRUE()), 
                        "Last rate", LASTNONBLANK(Charges[Charge], TRUE())),
                    "Change", [Last rate]<>[First rate]
                ), 
                [Last rate]<[First rate]
            )
return 
    countrows(gp)

 

 

 

 

 

Here's a link to a test pbix https://drive.google.com/file/d/1ob-94FmdOAwr_NwaIgi2YxL0-G0Qk8Bs/view?usp=share_link 

 

 

1 ACCEPTED SOLUTION
Mikelytics
Resident Rockstar
Resident Rockstar

HI @richardlynch 

 

Can you please try

 

 

Number of people with decreases = 

SUMX(
   VALUES(Table[Person]),
   var FirstDayRate = CALCULATE(MAX(Table[Charge],FIRSTDATE(Table[Date]))
   var LastDayRate = CALCULATE(MAX(Table[Charge],LASTDATE(Table[Date]))
   RETURN
   IF(LastDayRate<FirstDayRate,1,0)
)

 

 

OR

Number of people with decreases =

SUMX(
VALUES(Table[Person]),
var FirstDayRate = CALCULATE(MAX(Table[Charge],FILTER(Table,FIRSTDATE(Table[Date])))
var LastDayRate = CALCULATE(MAX(Table[Charge],FILTER(Table,LASTDATE(Table[Date])))
RETURN
IF(LastDayRate<FirstDayRate,1,0)
)

 

 

Best regards

Michael

-----------------------------------------------------

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

@ me in replies or I'll lose your thread.

-----------------------------------------------------

LinkedIn

------------------------------------------------------------------
Visit my blog datenhungrig which I recently started with content about business intelligence and Power BI in German and English or follow me on LinkedIn!

View solution in original post

2 REPLIES 2
richardlynch
Frequent Visitor

@Mikelytics thanks - I think that might be it!

Mikelytics
Resident Rockstar
Resident Rockstar

HI @richardlynch 

 

Can you please try

 

 

Number of people with decreases = 

SUMX(
   VALUES(Table[Person]),
   var FirstDayRate = CALCULATE(MAX(Table[Charge],FIRSTDATE(Table[Date]))
   var LastDayRate = CALCULATE(MAX(Table[Charge],LASTDATE(Table[Date]))
   RETURN
   IF(LastDayRate<FirstDayRate,1,0)
)

 

 

OR

Number of people with decreases =

SUMX(
VALUES(Table[Person]),
var FirstDayRate = CALCULATE(MAX(Table[Charge],FILTER(Table,FIRSTDATE(Table[Date])))
var LastDayRate = CALCULATE(MAX(Table[Charge],FILTER(Table,LASTDATE(Table[Date])))
RETURN
IF(LastDayRate<FirstDayRate,1,0)
)

 

 

Best regards

Michael

-----------------------------------------------------

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

@ me in replies or I'll lose your thread.

-----------------------------------------------------

LinkedIn

------------------------------------------------------------------
Visit my blog datenhungrig which I recently started with content about business intelligence and Power BI in German and English or follow me on LinkedIn!

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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