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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Anonymous
Not applicable

How to create a columns with range of numbers from values in rows

Hi Everyone,

 

So, what I need to do is create for each row, a range of numbers that considers the first value of the row, and the value in the next row.

 

For example:

 

1- For the Anchor Milestone for Q50 Community Task, I need to have two new columns that are "Range Start" and "Range End", which would be 2 for start, and 160 for end. 

 

2- For the Anchor Milestone for Agilsysy Community it would be Range Start 161, and Range End 321. 

 

Etc.

 

NaCingolani_0-1658942330631.png

I need to do this, so I can identify then in another table where I have several other Tasks which has their own ID (which dynamically changes) under which "main task" they fall under.

 

Any help is much appreciated,

 

Regards,

2 ACCEPTED SOLUTIONS
Anonymous
Not applicable

@Anonymous try using power query as below.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlLSUQpJLM42VIrViVYyNDOE8o3AfGMjmLwxmG9mCuObKMXGAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [RowNumber = _t, Task = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"RowNumber", Int64.Type}, {"Task", type text}}),
    #"Sorted Rows" = Table.Sort(#"Changed Type",{{"RowNumber", Order.Ascending}}),
    #"Added Index" = Table.AddIndexColumn(#"Sorted Rows", "Index", 0, 1, Int64.Type),
    #"Added Custom" = Table.AddColumn(#"Added Index", "Range End", each try #"Added Index" [RowNumber] { [Index]  + 1 }-1 otherwise null)
in
    #"Added Custom"

Mohan1029_0-1658943746726.png

Accept the solution if that works for you.

 

Thanks,

Mohan V.

View solution in original post

tamerj1
Super User
Super User

Hi @Anonymous 
Here is a sample file with the solution https://we.tl/t-BQUxx4q6jq

1.png

Range End = 
VAR PreviousStart = 
    MINX (
        FILTER ( Data, Data[RowNumber] > EARLIER ( Data[RowNumber] ) ),
        Data[RowNumber]
    )
RETURN
    IF ( 
        NOT ISBLANK ( PreviousStart ),
        PreviousStart - 1
    )

View solution in original post

14 REPLIES 14
tamerj1
Super User
Super User

Hi @Anonymous 
Here is a sample file with the solution https://we.tl/t-BQUxx4q6jq

1.png

Range End = 
VAR PreviousStart = 
    MINX (
        FILTER ( Data, Data[RowNumber] > EARLIER ( Data[RowNumber] ) ),
        Data[RowNumber]
    )
RETURN
    IF ( 
        NOT ISBLANK ( PreviousStart ),
        PreviousStart - 1
    )
Anonymous
Not applicable

Also works like a charm! Thanks!

@tamerj1 what am I missing here? We did the same thing including the "-1". You also added the test for blank but besides that it's the same. How did @Anonymous got the result he did with my code?

@SpartaBI 

Because his column is text type. 

SpartaBI
Community Champion
Community Champion

@tamerj1 I see, but how did you know that btw? He didn't share a screenshot of the model. Is it because you saw the abc 123 in Power query? 

Anyway, he should have accepted my solution also, especially that I was first 😜

@SpartaBI 
Actually not from power query. I knew from this: The numbers are aligned left like text 

1.png

And you are right. I should have been marked for your answer.

SpartaBI
Community Champion
Community Champion

Nice catch! 💪

Anonymous
Not applicable

@Anonymous try using power query as below.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlLSUQpJLM42VIrViVYyNDOE8o3AfGMjmLwxmG9mCuObKMXGAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [RowNumber = _t, Task = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"RowNumber", Int64.Type}, {"Task", type text}}),
    #"Sorted Rows" = Table.Sort(#"Changed Type",{{"RowNumber", Order.Ascending}}),
    #"Added Index" = Table.AddIndexColumn(#"Sorted Rows", "Index", 0, 1, Int64.Type),
    #"Added Custom" = Table.AddColumn(#"Added Index", "Range End", each try #"Added Index" [RowNumber] { [Index]  + 1 }-1 otherwise null)
in
    #"Added Custom"

Mohan1029_0-1658943746726.png

Accept the solution if that works for you.

 

Thanks,

Mohan V.

Anonymous
Not applicable

Worked perfectly! The Each Try did the trick!

 

Thanks Mohan!

SpartaBI
Community Champion
Community Champion

@Anonymous if you want it in DAX so you can add in the model this caclulated column for range end:

 

Range End = 
MINX(
	FILTER(
		'Table',
		'Table'[RowNumber] > EARILER('Table'[RowNumber])
	),
	'Table'[RowNumber]
) - 1

 


For range stat it's just equal to the value you already have in the row number.



2022-05-19 17_30_22-Re_ Need help on DAX function with measure vs colu... - Microsoft Power BI Commu.png


Full-Logo11.png

SpartaBI_3-1652115470761.png   SpartaBI_1-1652115142093.png   SpartaBI_2-1652115154505.png

Showcase Report – Contoso By SpartaBI

Anonymous
Not applicable

Hi SpartaBI,

 

Thanks for your support. I tried the calculated DAX column you provided, but the result is not the correct. Am I doing something wrong?

 

NaCingolani_0-1658943545673.png

 

Hi @Anonymous 
except of the "-1",  @SpartaBI's solution is correct you just need to set the data type of the RowNumber column to intiger from power query.

tamerj1
Super User
Super User

Hi @Anonymous 
That would be much easier using DAX. If you are interested in DAX calculated columns solution please share the same sample dat as copy/paste to prepare a sample file for you. Thank you

Anonymous
Not applicable

RowNumberTask

2Anchor Milestones for Q50 Community
161Anchor Milestones for Agilysys Community
322Infrastructure: Core
654Infrastructure: Network
699Infrastructure: Service Desk
791Infrastructure: Technical Operations Center (MTOC)
836Travel Innovation Platform (TIP)
1178BTO: Change Management
1180BTO: Deployment
1182BTO: Learning
1184BTO: UX/UI, XD, Business Process
1186CRS
1632Revised ACRS
1734Data Analytics & Reporting
1817Data Management
1878Data Migration
2490Impacted System - Digital: Comms
2573Impacted System - Digital: On-Site Digital (OSD)
2615Impacted System - Digital: Property & Product
2679Impacted System - Digital: Recognition
2713Impacted System - Digital: Search
2747Impacted System - Digital: Shop / Book
2780Impacted System - Digital: Group
2814Impacted System - Distribution
3205Impacted System - Empower Guest Services (GXP, CEC, ARM)
3404Impacted System - Finance
3529Impacted System - Group Inventory Portal
3538Impacted System - Hotel Ops: Integrations
4491Impacted System - Loyalty Earn
4518Impacted System - Loyalty: Redeem
4536Impacted System - Loyalty: Member Benefits
4554Impacted System - Loyalty: Loyalty Platform
4571Impacted System - Loyalty: Risk Management, Reporting & Controls
4593Impacted System - Loyalty: Funding & Reconciliation
4616Impacted System - Order Domain
4785Impacted System - Payments
4872Impacted System - Reservations
5045Impacted System - Revenue Mgmt: HPP
5107Impacted System - Revenue Mgmt: MarRFP, Pgoos
5171Impacted System - Revenue Mgmt: OY
5307Impacted System - Revenue Mgmt: TY
5386Impacted System - Sales: Associate Facing Reservation App Phase 1
5483Impacted System - Sales: Associate Facing Reservation App Phase 2
5591Impacted System - Sales: CEC/Property
5603Impacted System - Sales: Corp
5723Impacted System - Sales: Group
5873Impacted System - Sales: Omaha Billing
5898Impacted System - Sales: OSCAR
5935Privacy
5964Quality Engineering
6010Security
6093Technical Release
6223Agilysys (Vendor Plan)
6257APMS (Vendor Plan)
6291Auto-Room Assignments (ARA)
6325Opera Cloud (Vendor Plan)
6359Point-of-Sale (POS)
6393Single Pane of Glass (SPOG)

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.