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! Learn more

Reply
Troyes
Frequent Visitor

DAX - Create calculated column

Hi,

 

I'm trying to create a new column [New Qty] using DAX which convert the [Diff Qty] to the max values of [Usage Qty] in the same row and extend the [New Qty] to the next row until the sum equals the [Diff Qty], based on Product ID. Could anyone help me on that? Thanks.

 

1.PNG

1 ACCEPTED SOLUTION
v-alq-msft
Community Support
Community Support

Hi, @Troyes 

You can click ‘Edit Queries’ to enter into the Query Editor, go to  ‘Add Column’ -> click ‘Index Column’ to add index column (start from 0).

cc.png

Then, you can create a calculated column as follows:

New QTY =

VAR t =

FILTER (

'Table',

[Product] = EARLIER ( 'Table'[Product] )

&& [Index] < EARLIER ( 'Table'[Index] )

)

VAR totalDiff =

CALCULATE ( SUM ( 'Table'[DIFF QTY] ), t )+[DIFF QTY]

VAR minleft =

CALCULATE ( SUM ( 'Table'[Usage QTY] ), t )

RETURN

IF (

minleft > totalDiff,

0,

IF (

[DIFF QTY] <> 0,

[Usage QTY],

IF (

minleft = 0,

0,

IF ( minleft + [Usage QTY] > totalDiff, totalDiff - minleft, [Usage QTY] )

)

)

)

 

Result:

xxx.png

If I misunderstand the your thoughts, please inform me of your expected output. I am glad to solve the problem for you.

 

Best Regards,

Allan

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-alq-msft
Community Support
Community Support

Hi, @Troyes 

You can click ‘Edit Queries’ to enter into the Query Editor, go to  ‘Add Column’ -> click ‘Index Column’ to add index column (start from 0).

cc.png

Then, you can create a calculated column as follows:

New QTY =

VAR t =

FILTER (

'Table',

[Product] = EARLIER ( 'Table'[Product] )

&& [Index] < EARLIER ( 'Table'[Index] )

)

VAR totalDiff =

CALCULATE ( SUM ( 'Table'[DIFF QTY] ), t )+[DIFF QTY]

VAR minleft =

CALCULATE ( SUM ( 'Table'[Usage QTY] ), t )

RETURN

IF (

minleft > totalDiff,

0,

IF (

[DIFF QTY] <> 0,

[Usage QTY],

IF (

minleft = 0,

0,

IF ( minleft + [Usage QTY] > totalDiff, totalDiff - minleft, [Usage QTY] )

)

)

)

 

Result:

xxx.png

If I misunderstand the your thoughts, please inform me of your expected output. I am glad to solve the problem for you.

 

Best Regards,

Allan

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi @v-alq-msft 

 

Thanks for your reply. It works fine for me.

Helpful resources

Announcements
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!

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