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

Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.

Reply
Anonymous
Not applicable

Create multiple rows from single row based on conditions

Hi all,

 

I would like to turn the following table:

Criteria AmountMonth
Up1,0007
Down5003

 

into the following table:

Criteria AmountMonth
Up1,0007
Up1,0008
Up1,0009
Up1,00010
Up1,00011
Up1,00012
Down5003
Down5002
Down5001

 

If the criteria is "Up", then I will like to create multiple rows with value from the current month value (7) to 12 (the max month of the year).

If the criteria is "Down, then I will like to create multiple rows with value from the current month value (3) to 1 (the min month of the year).

 

Thank you very much for your guidance in advance.

 

 

Best regards,

1 ACCEPTED SOLUTION
AlB
Community Champion
Community Champion

@Anonymous 

If you want it in PQ, paste this M code in a blank query to see the steps:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCi1Q0lEyNDAwAFLmSrE60Uou+eV5QI4pWMhYKTYWAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Criteria = _t, Amount = _t, Month = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Criteria", type text}, {"Amount", Int64.Type}, {"Month", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each List.Numbers(if [Criteria]="Up" then [Month] else 1 , if [Criteria]="Up" then 12-[Month]+1 else [Month] )),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Month"}),
    #"Expanded Custom" = Table.ExpandListColumn(#"Removed Columns", "Custom"),
    #"Renamed Columns" = Table.RenameColumns(#"Expanded Custom",{{"Custom", "Month"}})
in
    #"Renamed Columns"

 

Please mark the question solved when done and consider giving kudos if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

 

SU18_powerbi_badge

 

View solution in original post

3 REPLIES 3
AlB
Community Champion
Community Champion

Hi @Anonymous 

You could do it also in PQ, but I believe it will be faster in DAX. Create a calculated table, where Table1 is the first table you show:

 

NewTable1 =
GENERATE (
    SUMMARIZE ( Table1, Table1[Criteria], Table1[Amount] ),
    VAR criteria_ =
        CALCULATE ( DISTINCT ( Table1[Criteria] ) )
    VAR month_ =
        CALCULATE ( DISTINCT ( Table1[Month] ) )
    RETURN
        GENERATESERIES (
            IF ( criteria_ = "Up", month_, 1 ),
            IF ( criteria_ = "Up", 12, month_ )
        )
)

 

 

Please mark the question solved when done and consider giving kudos if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

 

SU18_powerbi_badge

AlB
Community Champion
Community Champion

@Anonymous 

If you want it in PQ, paste this M code in a blank query to see the steps:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCi1Q0lEyNDAwAFLmSrE60Uou+eV5QI4pWMhYKTYWAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Criteria = _t, Amount = _t, Month = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Criteria", type text}, {"Amount", Int64.Type}, {"Month", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each List.Numbers(if [Criteria]="Up" then [Month] else 1 , if [Criteria]="Up" then 12-[Month]+1 else [Month] )),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Month"}),
    #"Expanded Custom" = Table.ExpandListColumn(#"Removed Columns", "Custom"),
    #"Renamed Columns" = Table.RenameColumns(#"Expanded Custom",{{"Custom", "Month"}})
in
    #"Renamed Columns"

 

Please mark the question solved when done and consider giving kudos if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

 

SU18_powerbi_badge

 

Anonymous
Not applicable

Thank you very much for your help. You make it so easy.

 

My apology for not stating I want the solution in PQ.

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Kudoed Authors