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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
NilsPR
Frequent Visitor

Calculate a positive number and a negative number according to a special rule

Hello 

 

I have a table with 4 important columns :

  • Movement : 1 or 2 
  • Quantity 
  • ID of purchase for each line 
  • Date

The movement 1 corresponds to a orderquantity and the movement 2 corresponds to a cancellation of 1 of the movement 1 thanks to the ID of purchase. So for example on the screenshot we can see a deliver an order quantity the 14 of February of 15.360 and the 19 a cancelation of the same quantity. You can see the ID of purchase is the same. So, how can I calculate to have 0 for this ID for example.

NilsPR_0-1711449569095.png

 

 

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

Hi @NilsPR ,

I create a new table as you mentioned.

vyilongmsft_0-1711503365974.png

Then I create a calculated column and here is the DAX code.

Column =
SUMX (
    FILTER (
        'Table',
        'Table'[ID of purchase for each line]
            = EARLIER ( 'Table'[ID of purchase for each line] )
    ),
    'Table'[Quantity]
)

Finally you will get the result you want.

vyilongmsft_1-1711503508004.png

 

 

 

Best Regards

Yilong Zhou

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-yilong-msft
Community Support
Community Support

Hi @NilsPR ,

I create a new table as you mentioned.

vyilongmsft_0-1711503365974.png

Then I create a calculated column and here is the DAX code.

Column =
SUMX (
    FILTER (
        'Table',
        'Table'[ID of purchase for each line]
            = EARLIER ( 'Table'[ID of purchase for each line] )
    ),
    'Table'[Quantity]
)

Finally you will get the result you want.

vyilongmsft_1-1711503508004.png

 

 

 

Best Regards

Yilong Zhou

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

Hi @v-yilong-msft 

 

Thanks a lot for your help, it works well.

 

Best regards

Nils

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.