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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
jcabeza
Frequent Visitor

generate a list with two intervals power query

I have a few hours of beginning and end, and I want to generate a list to later expand in rows, but when the hours pass to the next day I need a list to be generated until 23 hours and then to start at zero and reach the end.

 

StartEndExpected result
231{23,0,1]
220[22,23,0}
2323{23}
2223{22,23}

 

I made this code, but didn't work

 

let
Origen = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjJW0lEyMFSK1QGyjUBsAwgbJA4k4OIgdiwA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Start = _t, End = _t]),
#"Tipo cambiado" = Table.TransformColumnTypes(Origen,{{"Start", Int64.Type}, {"End", Int64.Type}}),
#"Personalizada agregada" = Table.AddColumn(#"Tipo cambiado", "List", each try {[Start]..[End]} otherwise {[Start]..23,0..[End]}),
#"Se expandió Personalizado" = Table.ExpandListColumn(#"Personalizada agregada", "List")
in
#"Se expandió Personalizado"

 

*pd: excuse me if I have bad english, is not my native language

1 ACCEPTED SOLUTION
CNENFRNL
Community Champion
Community Champion

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjJW0lEyVIrVATKNgEwDCBMkCiTgwiB2LAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Start = _t, End = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Start", Int64.Type}, {"End", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each if [End]<[Start] then List.Transform({[Start]..[End]+24}, each if _>=24 then _-24 else _) else {[Start]..[End]}),
    #"Extracted Values" = Table.TransformColumns(#"Added Custom", {"Custom", each Text.Combine(List.Transform(_, Text.From), ","), type text})
in
    #"Extracted Values"

Screenshot 2021-06-03 213922.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

View solution in original post

1 REPLY 1
CNENFRNL
Community Champion
Community Champion

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjJW0lEyVIrVATKNgEwDCBMkCiTgwiB2LAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Start = _t, End = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Start", Int64.Type}, {"End", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each if [End]<[Start] then List.Transform({[Start]..[End]+24}, each if _>=24 then _-24 else _) else {[Start]..[End]}),
    #"Extracted Values" = Table.TransformColumns(#"Added Custom", {"Custom", each Text.Combine(List.Transform(_, Text.From), ","), type text})
in
    #"Extracted Values"

Screenshot 2021-06-03 213922.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

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

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.

Top Solution Authors
Top Kudoed Authors