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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anglonso02
Frequent Visitor

In DAX create a new column from a 1st one filterd by a 3rd one depending on intervals

Dear All

 

I am struggling to create a new column that copies the values from a first one but only the ones form an interval of a third

In the exampel below ( form excel) i ´d need the to get the column "Time beteween 1 and 2" by coping the column "Time" but only the rows between ( or equal ) to 1 and 2.  Leaving blank otherwise

 

Your help will be much appreciated

 

Anglonso02_0-1690993251519.png

Thanks

 

Anglo.

2 ACCEPTED SOLUTIONS
kpost
Super User
Super User

1)Use "Fill down" on your [class] column in power query so your second column becomes something like this:

class
1
1
1
2
2
2
2
2
1
1
2
2
2
etc.

Then, in Power Query, follow these instructions to add a row index WITHIN each group of values in your [class] column.
https://radacad.com/create-row-number-for-each-group-in-power-bi-using-power-query

so it looks like this:

class, row_index_in_group
1 , 1
1 , 2
1 , 3
2 , 1
2 , 2 
2 , 3
2 , 4
2 , 5
1 , 1
1 , 2
2 , 1
2 , 2
2 , 3

Now the logic should be readily apparent!

Time_between_1_and_2 =
SWITCH(
    TRUE(),
    [class] = 1, [time],
    [class] = 2 && [row_index_in_group] = 1, [time],
    BLANK()
)


In plain english, after you "fill down" and add the row index within each grouping of 1 and 2, it logically follows from your example that ANYTHING where the class is 1 needs to be included.  but when the class is 2, ONLY when it's the first instance of a 2 (the row_index_in_group is a 1).




//Mediocre Power BI Advice, but it's free!//

View solution in original post

Anglonso02
Frequent Visitor

Worked! Thanks for your helped. Appreciated

View solution in original post

3 REPLIES 3
Anglonso02
Frequent Visitor

Worked! Thanks for your helped. Appreciated

Anglonso02
Frequent Visitor

Ok, Thanks a lot for your prompt answers. i was about to reply right now but I will work on this new aproach you give it to me. I ´ll let you know my progress. Rgds !!

kpost
Super User
Super User

1)Use "Fill down" on your [class] column in power query so your second column becomes something like this:

class
1
1
1
2
2
2
2
2
1
1
2
2
2
etc.

Then, in Power Query, follow these instructions to add a row index WITHIN each group of values in your [class] column.
https://radacad.com/create-row-number-for-each-group-in-power-bi-using-power-query

so it looks like this:

class, row_index_in_group
1 , 1
1 , 2
1 , 3
2 , 1
2 , 2 
2 , 3
2 , 4
2 , 5
1 , 1
1 , 2
2 , 1
2 , 2
2 , 3

Now the logic should be readily apparent!

Time_between_1_and_2 =
SWITCH(
    TRUE(),
    [class] = 1, [time],
    [class] = 2 && [row_index_in_group] = 1, [time],
    BLANK()
)


In plain english, after you "fill down" and add the row index within each grouping of 1 and 2, it logically follows from your example that ANYTHING where the class is 1 needs to be included.  but when the class is 2, ONLY when it's the first instance of a 2 (the row_index_in_group is a 1).




//Mediocre Power BI Advice, but it's free!//

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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 Solution Authors