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
Anonymous
Not applicable

Calculate Remaining Items

Hello,

Any help in how to do this in Power Bi will be highly appreciated.

 

Given the data below:

StartCount = 100

 

Table1:

#       Used

1         20

2         30

3         15

4

5

 

I like to create two new columns with Rem and Rem% as below:

Also, if possible, I wish to leave the Rem and Rem% blank if there is no data in Used.

#       Used     Rem     Rem%

1         20        80        80%

2         30        50        50%

3         15        35         35%

4

5

 

Thanks in advance for your help.

 

Ahmed

   

1 ACCEPTED SOLUTION
mahoneypat
Employee
Employee

Here is a measure expression to do it.  I called your table Used (so you'll need to change that to your actual table name), and I renamed your "#" column to "Num".  To get your 2nd measure, just change the return as indicated in the comment.

 

Rem =
VAR vInitial = 100
VAR vThisNum =
    MIN ( Used[Num] )
VAR vUsedSoFar =
    CALCULATE (
        SUM ( Used[Used] ),
        ALL ( Used ),
        Used[Num] <= vThisNum
    )
RETURN
    vInitial - vUsedSoFar
// for Rem % use DIVIDE(vInitial - vUsedSoFar, vInitial)

 

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

5 REPLIES 5
Ashish_Mathur
Super User
Super User

Hi,

Do you not have a Date column in your dataset?  If you do, the measures becomes very simple.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

Hi Ashish,

Yes I do have date col as well, I wanted to keep it simple for the test case.

That date column would have made the measure simpler but if you already have a solution, it is fine.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
mahoneypat
Employee
Employee

Here is a measure expression to do it.  I called your table Used (so you'll need to change that to your actual table name), and I renamed your "#" column to "Num".  To get your 2nd measure, just change the return as indicated in the comment.

 

Rem =
VAR vInitial = 100
VAR vThisNum =
    MIN ( Used[Num] )
VAR vUsedSoFar =
    CALCULATE (
        SUM ( Used[Used] ),
        ALL ( Used ),
        Used[Num] <= vThisNum
    )
RETURN
    vInitial - vUsedSoFar
// for Rem % use DIVIDE(vInitial - vUsedSoFar, vInitial)

 

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Anonymous
Not applicable

Hi Pat,

The solution works just fine.

 Is there a simple way to keep the results blank if the used value is blank.

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.