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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Human
Frequent Visitor

Volume Used per day when there are refill in the day

Hi all, 

I want to create a calculated column where it could calculate the usage of the volume for the day. I have a set of data where there are a few days where the volume was being used normally and also one day where there are a refill on the volume.

 

I was hoping that for the normal day, the volume used would be (volume at the start of the day would - the volume at the end of the day) and for the day that has a refill, it could:

  1. Subtract the volume reading from the start of the day with the lowest volume reading of the day (before refill).
  2. Subtracting the Highest volume reading of the day (after refill) with the volume reading at the end of the day.

Eventually, for the day that have a refill, both subtracted value from no1 and no 2 will be added together and the result would be reflected in the calculated column. 

 

 timestampVolumeVolume Used
14/8/2023 6:0110300
14/8/2023 12:2710290
14/8/2023 23:5910300
15/8/2023 0:0010300
15/8/2023 0:0110300
15/8/2023 7:239940
15/8/2023 11:289190
15/8/2023 14:11884146
16/8/2023 0:008480
16/8/2023 7:488120
16/8/2023 10:387730
16/8/2023 10:397390
16/8/2023 17:487030
16/8/2023 23:59668180
17/8/2023 0:006680
17/8/2023 11:315950
17/8/2023 22:50522146
18/8/2023 0:005220
18/8/2023 8:354860
18/8/2023 12:024490
18/8/2023 14:044140
18/8/2023 14:055940
18/8/2023 14:069560
18/8/2023 14:0712910
18/8/2023 14:0816430
18/8/2023 14:0916800
18/8/2023 16:4816800
18/8/2023 16:4916800
18/8/2023 16:5016440
18/8/2023 23:501645143

The above was what I have been trying to achieve. Any help is very much appreciated. Thank you in advance.

1 ACCEPTED SOLUTION

Hi @Human ,

Thanks for your feedback. I updated the sample pbix file(see the attachment), please find the details in it. Please update the formula of calculated column [Volume Used] as below:

 

Volume Used = 
VAR _mintm =
    CALCULATE (
        MIN ( 'Table'[timestamp] ),
        FILTER ( 'Table', 'Table'[Date] = EARLIER ( 'Table'[Date] ) )
    )
VAR _maxtm =
    CALCULATE (
        MAX ( 'Table'[timestamp] ),
        FILTER ( 'Table', 'Table'[Date] = EARLIER ( 'Table'[Date] ) )
    )
VAR _mintmvalue =
    CALCULATE (
        MAX ( 'Table'[Volume] ),
        FILTER ( 'Table', 'Table'[timestamp] = _mintm )
    )
VAR _maxtmvalue =
    CALCULATE (
        MAX ( 'Table'[Volume] ),
        FILTER ( 'Table', 'Table'[timestamp] = _maxtm )
    )
VAR _minvalue =
    CALCULATE (
        MIN ( 'Table'[Volume] ),
        FILTER ( 'Table', 'Table'[Date] = EARLIER ( 'Table'[Date] ) )
    )
VAR _maxvalue =
    CALCULATE (
        MAX ( 'Table'[Volume] ),
        FILTER ( 'Table', 'Table'[Date] = EARLIER ( 'Table'[Date] ) )
    )
VAR _diff1 = _mintmvalue - _maxtmvalue
RETURN
    IF (
        'Table'[timestamp] = _maxtm,
        IF (
            ABS ( _diff1 ) <= 400,
            _diff1,
            ( _mintmvalue - _minvalue ) + ( _maxvalue - _maxtmvalue )
        ),
        0
    )

 

vyiruanmsft_0-1698201866677.png

Best Regards

Community Support Team _ Rena
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

7 REPLIES 7
v-yiruan-msft
Community Support
Community Support

Hi @Human ,

I created a sample pbix file(see the attachment), please chekc if that is what you want. You can create two calculated columns as below to get it:

Date = DATEVALUE('Table'[timestamp])
Volume Used = 
VAR _mintm =
    CALCULATE (
        MIN ( 'Table'[timestamp] ),
        FILTER ( 'Table', 'Table'[Date] = EARLIER ( 'Table'[Date] ) )
    )
VAR _maxtm =
    CALCULATE (
        MAX ( 'Table'[timestamp] ),
        FILTER ( 'Table', 'Table'[Date] = EARLIER ( 'Table'[Date] ) )
    )
VAR _minvalue =
    CALCULATE (
        MAX ( 'Table'[Volume] ),
        FILTER ( 'Table', 'Table'[timestamp] = _mintm )
    )
VAR _maxvalue =
    CALCULATE (
        MAX ( 'Table'[Volume] ),
        FILTER ( 'Table', 'Table'[timestamp] = _maxtm )
    )
RETURN
    IF ( 'Table'[timestamp] = _maxtm, _minvalue - _maxvalue, 0 )

vyiruanmsft_0-1698054524135.png

I have one doubt here: for the timestamp 18/8/2023 23:50, why the volume used is 143?

Best Regards

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

@v-yiruan-msft So on 18/8/2023 23:50, it has a refill. I understand that the original formula (volume at the start of the day would - the volume at the end of the day) cannot be used so I got 143 by:

 [(volume at day start - Lowest volume of the day) + (Highest Volume of the day - volume at day end)]

Hi @Human ,

Thanks for your feedback. I updated the sample pbix file(see the attachment), please find the details in it. Please update the formula of calculated column [Volume Used] as below:

 

Volume Used = 
VAR _mintm =
    CALCULATE (
        MIN ( 'Table'[timestamp] ),
        FILTER ( 'Table', 'Table'[Date] = EARLIER ( 'Table'[Date] ) )
    )
VAR _maxtm =
    CALCULATE (
        MAX ( 'Table'[timestamp] ),
        FILTER ( 'Table', 'Table'[Date] = EARLIER ( 'Table'[Date] ) )
    )
VAR _mintmvalue =
    CALCULATE (
        MAX ( 'Table'[Volume] ),
        FILTER ( 'Table', 'Table'[timestamp] = _mintm )
    )
VAR _maxtmvalue =
    CALCULATE (
        MAX ( 'Table'[Volume] ),
        FILTER ( 'Table', 'Table'[timestamp] = _maxtm )
    )
VAR _minvalue =
    CALCULATE (
        MIN ( 'Table'[Volume] ),
        FILTER ( 'Table', 'Table'[Date] = EARLIER ( 'Table'[Date] ) )
    )
VAR _maxvalue =
    CALCULATE (
        MAX ( 'Table'[Volume] ),
        FILTER ( 'Table', 'Table'[Date] = EARLIER ( 'Table'[Date] ) )
    )
VAR _diff1 = _mintmvalue - _maxtmvalue
RETURN
    IF (
        'Table'[timestamp] = _maxtm,
        IF (
            ABS ( _diff1 ) <= 400,
            _diff1,
            ( _mintmvalue - _minvalue ) + ( _maxvalue - _maxtmvalue )
        ),
        0
    )

 

vyiruanmsft_0-1698201866677.png

Best Regards

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

Might be easier to use a graphical solution.

 

lbendlin_0-1698074700232.png

 

When is a refill a refill and not just a data fluke?  Is any positive change considered to be a refill? For example on 8/14 you go from 1030 to 1029 to 1030. is that a refill?

@lbendlin For the change to be considered refill, it should be a significant posistive change of volume so on 8/14, it would be considered that it is only a small fluctuation on the reading. Generally, a change of more than 400 volume would be considered as a refill.

lbendlin
Super User
Super User

Please provide sample data (with sensitive information removed) that covers your issue or question completely, in a usable format (not as a screenshot). Leave out anything not related to the issue.
If you are unsure how to do that please refer to https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-...
Please show the expected outcome based on the sample data you provided.

If you want to get answers faster please refer to https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447...

@lbendlin Thank you for the advice. I have revise my inquiry as stated above. Please let me know if there's any other issues.

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.