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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
manvpbi
Frequent Visitor

How to manage values from an actual hour and the values from one or two hours before and substract

Hello everyone, Im getting frustrated with this topic. I want to create a visualization like figure 1. where the grey part is a sum value through hours (text type), that represent how much the business grows in hours, the red part represents the difference between the value of an specific hour and the hour before. Example: at 9am Sales = 10$ and 7am Sales = 7$ then your red value will be 3$

 

Figure 1

manvpbi_0-1653511613315.png

 

Figure 2.

Dataset example

FYI, I have hourly cuts like (6am - 7am - 9am - 11am -12pm - 1pm - 3pm - 5pm - 7pm - 8pm and 10pm)

Date(int)                 ProductID     Hour(Text)         Sales

manvpbi_1-1653512154965.png

 

I already read a lot of information and tried a lot of distinct formulas (dax/ power query) but I didnt have the expected results.

 

Hope you can help me a bit with this .

 

Greetings

 

 

1 ACCEPTED SOLUTION

Hi, @manvpbi 

 

You can try the following methods.

Measure:

Sum = CALCULATE(SUM('Table'[#VOL]),FILTER(ALL('Table'),[FK_DATE]=SELECTEDVALUE('Table'[FK_DATE])))
Difference =
CALCULATE (
    SUM ( 'Table'[#VOL] ),
    FILTER (
        ALL ( 'Table' ),
        [FK_DATE] = SELECTEDVALUE ( 'Table'[FK_DATE] )
            && [HOURS] = MAX ( 'Table'[HOURS] )
    )
)
    - CALCULATE (
        SUM ( 'Table'[#VOL] ),
        FILTER (
            ALL ( 'Table' ),
            [FK_DATE] = SELECTEDVALUE ( 'Table'[FK_DATE] )
                && [HOURS] = MIN ( 'Table'[HOURS] )
        )
    )

vzhangti_0-1654074885793.png

Is this the output you expect?

 

Best Regards,

Community Support Team _Charlotte

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

4 REPLIES 4
manvpbi
Frequent Visitor

Here some data examples

FK_DATE (int)HOURS(text)#VOL(int)
2022031106:00208
2022031406:0045
2022031506:000
2022031606:00268
2022031706:0076
2022031806:00195
2022031906:00114
2022032506:00133
2022040106:005357
2022040506:0087
2022040606:0085
2022040706:0071
2022040806:0051
2022040906:0089
2022041106:0059
2022041206:00131
2022041306:00156
2022041406:00161
2022041506:00265
2022041606:00188
2022041806:0022
2022041906:00213
2022042006:00323
2022042106:00357
2022042206:00151
2022042306:00146
2022042806:00145
2022042906:00230
2022043006:001171
2022050306:00233
2022050406:0054
2022050506:0033
2022050706:00798
2022050906:00119
2022051006:001428
2022051106:0093
2022051206:0048
2022051306:00210
2022051406:00117
2022051606:00104
2022051706:0052
2022051906:0037
2022052006:0092
2022052106:00118
2022052306:0046
2022052406:00255
2022052506:00358
2022052606:00132
2022050607:0077
2022042309:001582
2022042809:00819
2022042909:00513
2022043009:001171
2022050309:001344
2022050409:00251
2022050509:00154
2022050609:00202
2022050709:00978
2022050909:00229
2022051009:001476
2022051109:00567
2022051209:00714
2022051309:00354
2022051409:00315
2022051609:00410
2022051709:00255
2022051809:00136
2022051909:00347
2022052009:00186
2022052109:00264
2022052309:00116

Hi, @manvpbi 

 

You can try the following methods.

Measure:

Sum = CALCULATE(SUM('Table'[#VOL]),FILTER(ALL('Table'),[FK_DATE]=SELECTEDVALUE('Table'[FK_DATE])))
Difference =
CALCULATE (
    SUM ( 'Table'[#VOL] ),
    FILTER (
        ALL ( 'Table' ),
        [FK_DATE] = SELECTEDVALUE ( 'Table'[FK_DATE] )
            && [HOURS] = MAX ( 'Table'[HOURS] )
    )
)
    - CALCULATE (
        SUM ( 'Table'[#VOL] ),
        FILTER (
            ALL ( 'Table' ),
            [FK_DATE] = SELECTEDVALUE ( 'Table'[FK_DATE] )
                && [HOURS] = MIN ( 'Table'[HOURS] )
        )
    )

vzhangti_0-1654074885793.png

Is this the output you expect?

 

Best Regards,

Community Support Team _Charlotte

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

 

Thanks for your answer @v-zhangti, I did some changes to your measures and I got the results.

MEASURE#1

CALCULATE(SUM([VOLUMEN]),
FILTER(ALL('TABLE'),[FK_DATE]=SELECTEDVALUE('TABLE'[FK_DATE]) && 'TABLE'[HOUR] = SELECTEDVALUE('TABLE'[HOUR])))
 
MEASURE#2
var ACTUAL_HOUR = SELECTEDVALUE('TABLE'[HOUR])
var PAST_HOUR =
calculate(MAX('TABLE'[HOUR]),
FILTER
(ALLselected('TABLE'),
[HOUR]< ACTUAL_HOUR))
 
var MAX_VALUE =
CALCULATE (
SUM ( 'TABLE'[VOLUMEN]),
FILTER (
ALL('TABLE'),
'TABLE'[FK_DATE] = SELECTEDVALUE ( 'TABLE'[FK_DATE] )
&& 'TABLE'[HOUR] = ACTUAL_HOUR
)
)
var MIN_VALUE =
CALCULATE (
SUM ( 'TABLE'[VOLUMEN]),
FILTER (
ALL( 'TABLE'),
[FK_DATE] = SELECTEDVALUE ('TABLE'[FK_DATE])
&& 'TABLE'[HOUR] = PAST_HOUR
)
)
var DIFF = MAX_VALUE - MIN_VALUE
return
Diff
 
Whitewater100
Solution Sage
Solution Sage

Hi:

Can you share some example data? Can be image of your data model and pasting excel right into your reply?

 

Thanks..

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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