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
Anonymous
Not applicable

Need Help in Calculating the Read total by serial no

Hi All,

 

I need help in find the total read for an entire year of each installation number.

 

Here is a sample data and the output which i am looking for.

NumberSerial NumberDateReasonRead
900000216923606/13/2022 0:0011932
900000216923605/12/2022 0:0011872
900000216923605/9/2022 0:00101863
900000216923604/11/2022 0:0011671
900000216923603/11/2022 0:0011230
900000216923602/10/2022 0:001779
900000216923601/14/2022 0:001499
9000002169236012/13/2021 0:0010
9000002169236012/8/2021 0:00210
9000002169242412/7/2021 0:00221086
9000002169242411/12/2021 0:001689
9000002169242410/14/2021 0:001350
900000216924249/14/2021 0:00176
900000216924248/13/2021 0:00111
900000216924248/12/2021 0:00210
900000215731578/11/2021 0:002214150
900000215731577/12/2021 0:00114113
     
     
     
     
Output    
900000216923606/13/2022 0:0011932
900000216923608/13/2021 0:00111
9000002169242412/7/2021 0:00221086
9000002169242412/13/2021 0:0010
900000215731578/11/2021 0:002214150
900000215731577/12/2021 0:00114113
Final Output    
Numbertotal readsFormula  
90000023044=(E88-E89)+(E90-E91)+(E92-E93)  
1 ACCEPTED SOLUTION
lbendlin
Super User
Super User

So for each serial number you want to find the difference between the oldest and newest readings, and then you want to sum these differences?

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("jdLhCoUgDAXgV7n4O3BnM6f3VaL3f42sJK64xQ2MqPPhNtu2UOm8OCwBubJkak85QiIT84e+dL7Auapw2BdbrBE8i6Jvoo7gupUsrkgRmPfICleIKVjIFRxBk1CtLkBEmkCqL4D7cPEr/Ipavgxx9vKJ053XMX99p5J9gn56Q0m5WE10Qb3tQcjql1UtoH5NxZoSrKN+8vzHmFaVtu48jDElzD08Rq0xNYL2z+4H", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Number = _t, #"Serial Number" = _t, Date = _t, Reason = _t, Read = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type datetime}, {"Read", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Serial Number"}, {{"Rows", each _, type table [Number=nullable text, Serial Number=nullable text, Date=nullable datetime, Reason=nullable text, Read=nullable number]}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Delta", each List.First([Rows][Read])-List.Last([Rows][Read])),
    #"Changed Type1" = Table.TransformColumnTypes(#"Added Custom",{{"Delta", Int64.Type}})
in
    List.Sum(#"Changed Type1"[Delta])

How to use this code: Create a new Blank Query. Click on "Advanced Editor". Replace the code in the window with the code provided here. Click "Done".

 

 

View solution in original post

2 REPLIES 2
v-xiaotang
Community Support
Community Support

Hi @Anonymous 

I just want to confirm if you resolved this issue? If yes, you can accept the answer helpful as the solution or share you method and accept it as solution, thanks for your contribution to improve Power BI.

If you need more help, please let me know.

 

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.

lbendlin
Super User
Super User

So for each serial number you want to find the difference between the oldest and newest readings, and then you want to sum these differences?

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("jdLhCoUgDAXgV7n4O3BnM6f3VaL3f42sJK64xQ2MqPPhNtu2UOm8OCwBubJkak85QiIT84e+dL7Auapw2BdbrBE8i6Jvoo7gupUsrkgRmPfICleIKVjIFRxBk1CtLkBEmkCqL4D7cPEr/Ipavgxx9vKJ053XMX99p5J9gn56Q0m5WE10Qb3tQcjql1UtoH5NxZoSrKN+8vzHmFaVtu48jDElzD08Rq0xNYL2z+4H", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Number = _t, #"Serial Number" = _t, Date = _t, Reason = _t, Read = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type datetime}, {"Read", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Serial Number"}, {{"Rows", each _, type table [Number=nullable text, Serial Number=nullable text, Date=nullable datetime, Reason=nullable text, Read=nullable number]}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Delta", each List.First([Rows][Read])-List.Last([Rows][Read])),
    #"Changed Type1" = Table.TransformColumnTypes(#"Added Custom",{{"Delta", Int64.Type}})
in
    List.Sum(#"Changed Type1"[Delta])

How to use this code: Create a new Blank Query. Click on "Advanced Editor". Replace the code in the window with the code provided here. Click "Done".

 

 

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

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

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.