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
molzmad
Helper I
Helper I

Occupany, Culmulative total help

Hi, i basically have a column labeled occupancy 2, which is a culumaltive total of people entering or exiting a building, im wanting to understand how to modify my DAX so that the occupancy 2 cant go below zero, if anyone would be able to help it would be greatly appreciated 🙂

molzmad_0-1618571998918.png

 

13 REPLIES 13
amitchandak
Super User
Super User

@molzmad ,Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.

 

Try

a new column =

if([Occupancy] <0 , 0, [Occupancy])

Hi, i have attached a sample here, i tried do the new column and it didnt work :(, thanks so much for taking a look i really appreciate it 🙂

https://drive.google.com/file/d/11ubbPcRiZDj--3osMqBtXziRB4mZ5r3m/view?usp=sharing 

I basically need it to do a running total, but if the total goes below zero then to make it zero, as i dont want the occupancy levels going into minus 🙂

Hi @molzmad ,

 

It's not clear to me. I did a test. Is the following result what you want?

v-yuaj-msft_0-1618904596761.png

Column =
VAR x1 =
    CALCULATE (
        SUM ( 'Enliteon_Office_Test Count_Events'[Ins_Outs] ),
        FILTER (
            ALL ( 'Enliteon_Office_Test Count_Events' ),
            [Custom] <= EARLIER ( 'Enliteon_Office_Test Count_Events'[Custom] )
        )
    )
RETURN
    IF ( x1 < 0, 0, x1 )

Hope that's what you were looking for.

Best Regards,

Yuna

 

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

Hi,
Yes thats right, but how come it doesnt start counting from the beggining i.e. top row? Is there anyway to implement this? For example its counting some of the ins as 0

Hi @molzmad ,

 

Thanks for your reply. I think it does count from the beginning. You can sort the "timestamp" column ascending. 

v-yuaj-msft_0-1619085915424.png

Result:

v-yuaj-msft_1-1619085941800.png

Hope that's what you were looking for.

Best Regards,

Yuna

 

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

Hi, 
yeah it does seem to work but i mean for example you have put above, in the second row, the value for Ins_Outs = 1, so "column" should = 1  if that makes sense ?

Hi @molzmad ,

 

So you want to create a new column, where the negative value is zero and the positive value remains the same, right?

 

Best Regards,

Yuna

Yeah basically, i just want the accumulated column to count but not go below zero :),

Thanks :),
Molly

Hi @molzmad ,

 

Is the following result what you want? (column 2)

v-yuaj-msft_0-1619172190087.png

 

Best Regards,

Yuna

Hi 🙂 column two looks right but i just want it to count accumulatively i.e. column 2 would look like this :

molzmad_0-1619183951246.png

 

Hi @molzmad ,

 

Based on your description, you can create two calculated columns as follows.

Rank =
RANKX ( ALL ( 'Enliteon_Office_Test Count_Events' ), [timestamp],, ASC )
Test_value =
VAR x1 =
    MAXX (
        FILTER (
            ALL ( 'Enliteon_Office_Test Count_Events' ),
            [Rank] <= EARLIER ( 'Enliteon_Office_Test Count_Events'[Rank] )
                && [Ins_Outs] < 0
        ),
        [Rank]
    )
RETURN
    [Rank] - x1

Result:

v-yuaj-msft_0-1619416891910.png

Hope that's what you were looking for.

Best Regards,

Yuna

 

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

Hi almost, i just want the -1 to minus from the prior number i.e. 3,2,1 rather than the -1 equal zero if that makes sense, but just not allow the column to go below zero, like an accumulative sum that cant go below zero 

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.