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
psantosADS
Regular Visitor

calculate the value between two date as max an min

Hello,

 

Here's my problem:

I need to know the difference between two numbers based on the time. The first number is the first value recorded at the beginning of the day, the second number is the last value recorded at the end of the day.

Max-Min does not work because during the day there may be lower values ​​than those recorded at the beginning of the day.

 

Thanks

1 ACCEPTED SOLUTION

Sure. See attached.

View solution in original post

9 REPLIES 9
psantosADS
Regular Visitor

Thank you ValtteriN

 

Its not working.

Here is an exemple of my table:

 

I need to calculate 1860-1658.

This as to work every day. Any ideas?

FECHAVALOR
21/12/2021 00:011658
21/12/2021 18:041826
21/12/2021 18:431902
21/12/2021 18:571861
21/12/2021 19:551926
21/12/2021 20:032002
21/12/2021 20:132036
21/12/2021 21:371912
21/12/2021 21:451802
21/12/2021 22:042098
21/12/2021 22:162074
21/12/2021 22:241940
21/12/2021 22:411717
21/12/2021 22:501675
21/12/2021 22:581830
21/12/2021 23:331734
21/12/2021 23:401476
21/12/2021 23:581860

 

This is easier if you separate your FECHA column into a Date column and a Time column (which is good practice anyway).

 

If you do this, then you should be able to write a measure like this:

VAR Summary =
    ADDCOLUMNS (
        SUMMARIZE (
            Table1,
            Table1[Date],
            "MinTime", MIN ( Table1[Time] ),
            "MaxTime", MAX ( Table1[Time] )
        ),
        "MinVal", CALCULATE ( SUM ( Table1[VALOR] ), Table1[Time] = EARLIER ( [MinTime] ) ),
        "MaxVal", CALCULATE ( SUM ( Table1[VALOR] ), Table1[Time] = EARLIER ( [MaxTime] ) )
    )
RETURN
    SUMX ( Summary, [MaxVal] - [MinVal] )

 

Thanks,

 

still not working...

maybe I explained it wrong.
For the example below, I look for the result of 706 (494.732-494026) obtained on day 20 for the variable 1047

telegestão.JPG

 

It works fine for me after defining the date and time columns.

AlexisOlson_0-1643645376362.png

You get zeros at the time granularity though since there is only one time in the filter context. This can be changed by removing that filter context.

Can you send me the pbix file?

Thanks

Sure. See attached.

Can you share the data in a format I can copy and paste from?

Here's my pbix file:

PBIX File 

ValtteriN
Super User
Super User

Hi,

Try something like this:

var _cdate = DATE(YEAR(Table[Time]),MONTH(Table[Time]),DAY(Table[Time]))
var _minTime = Calculate(MIN(Table[Time]),ALL(Table),DATE(YEAR(Table[Time]),MONTH(Table[Time]),DAY(Table[Time]))=_cdate)
var _maxTime =
Calculate(MAX(Table[Time]),ALL(Table),DATE(YEAR(Table[Time]),MONTH(Table[Time]),DAY(Table[Time]))=_cdate)
var _maxvalue =Calculate(MAX(Table[Value]),ALL(Table),Table[Time]=_maxTime)
var _minvalue  =Calculate(MAX(Table[Value]),ALL(Table),Table[Time]=_minTime)
return

_maxvalue-_minvalue


I hope this post helps to solve your issue and if it does consider accepting it as a solution and giving the post a thumbs up!






Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




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.