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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
sabeensp
Helper IV
Helper IV

Looping Through Records

Hello All,

I have a data set in table as shown below:

What I need to do is that loop through the records by date, if Cust ID has 2 or more records on the same day or diffrent dates, with the TYPE value =  A or D, then give me those records and subtract High value from the Low value.

Data.jpg

Desired Result

Result.jpg

 

Thanks

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hey @sabeensp 

It works just fine for me, with the sample you have provided.

2019-06-28 09_10_10-papercut - Remote Desktop Connection.png

You can share your current data, then we can further assist you.

Cheers!
A

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hey @sabeensp 

Try the following:

DIFF =
VAR NUM_OF_SHOWS =
    CALCULATE (
        COUNTROWS ( T11 ),
        FILTER (
            T11,
            T11[CUST_ID]
                = EARLIER ( T11[CUST_ID] )
        ),
        FILTER (
            T11,
            T11[TYPE] = "A"
                || T11[TYPE] = "D"
        )
    )
RETURN
    IF (
        NUM_OF_SHOWS > 0,
        ABS ( T11[HIGH] - T11[LOW] ),
        -1
    )

Then filter the visual where DIFF is not blank and above 0.

 

Good Luck!
A

@Anonymous  I get an error Earler/Earliset refers to an earler row context, which does not exsist.

Anonymous
Not applicable

Hey @sabeensp 

It works just fine for me, with the sample you have provided.

2019-06-28 09_10_10-papercut - Remote Desktop Connection.png

You can share your current data, then we can further assist you.

Cheers!
A

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
Top Kudoed Authors