cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

Reply
kageyoshi777
Frequent Visitor

value for min/max date for each item in table

I'm trying to show the difference between lowest/highest value of real estate offers next to eachother in one table.

I've got table like this.

 

advert_numberdata_downloadprice
11102.01.2020100
11103.01.2020200
11104.01.2020300

 

And measures..

 

 

Mindate = 
CALCULATE(MAX(estate_data[price]), FIRSTDATE(estate_data[date_download]))
Maxdate = 
CALCULATE ( max ( estate_data[price] ), LASTDATE(estate_data[date_download]))

 

 

 

But for some reason in few cases I dont see price for min/max date like in this example. 

Where I made an error? 

err.png

1 ACCEPTED SOLUTION

Hi  @kageyoshi777 ,

I created a sample pbix file(see attachment) for you, please check whether that is what you want. You can update the formula of measure [Mindate] and [Maxdate] as below:

Mindate = 
VAR _seladvert =
    SELECTEDVALUE ( 'estate_data'[advert_number] )
VAR _mindate =
    CALCULATE (
        MIN ( 'estate_data'[data_download] ),
        FILTER (
            ALLSELECTED ( 'estate_data' ),
            'estate_data'[advert_number] = _seladvert
        )
    )
RETURN
    CALCULATE (
        MAX ( 'estate_data'[price] ),
        FILTER (
            ALLSELECTED ( 'estate_data' ),
            'estate_data'[advert_number] = _seladvert
                && 'estate_data'[data_download] = _mindate
        )
    )
Maxdate = 
VAR _seladvert =
    SELECTEDVALUE ( 'estate_data'[advert_number] )
VAR _maxdate =
    CALCULATE (
        MAX ( 'estate_data'[data_download] ),
        FILTER (
            ALLSELECTED ( 'estate_data' ),
            'estate_data'[advert_number] = _seladvert
        )
    )
RETURN
    CALCULATE (
        MAX ( 'estate_data'[price] ),
        FILTER (
            ALLSELECTED ( 'estate_data' ),
            'estate_data'[advert_number] = _seladvert
                && 'estate_data'[data_download] = _maxdate
        )
    )

yingyinr_0-1657185716220.png

If the above one can't help you get the desired result, please provide more sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community

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

3 REPLIES 3
ValtteriN
Super User
Super User

Hi,

For these kind of calculations I recommend using thins kind of pattern:

 

Maxdate = 
var _mdate = CALCULATE ( max (estate_data[date_download]),All(estate_data[advert_number]))return

CALCULATE ( max ( estate_data[price] ), all(estate_data[date_download]),estate_data[date_download]=_mdate)

 


The idea here is to first define the desired date in variable then remove some filter context using all and finally returnin filters to the calculation by using the variable defined. You might need to adjust the variable and ALL to get the desired outcome but the idea remains the same. If you have calendar table instead of using ALL(estate_data[date_download]) in the calculate you can use ALL(calendar).

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!

My LinkedIn: https://www.linkedin.com/in/n%C3%A4ttiahov-00001/





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

Proud to be a Super User!




Hi, this solution does not solve my problem 😑. Of course for some "adverts" it works, like old measures worked too.

 

11.png

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

But for others still nothing. 

12.png

 

 

 

 

 

 

 

 

 

 

 

In this case I'm not using any data tables etc. Only plain data table like in my first post

Hi  @kageyoshi777 ,

I created a sample pbix file(see attachment) for you, please check whether that is what you want. You can update the formula of measure [Mindate] and [Maxdate] as below:

Mindate = 
VAR _seladvert =
    SELECTEDVALUE ( 'estate_data'[advert_number] )
VAR _mindate =
    CALCULATE (
        MIN ( 'estate_data'[data_download] ),
        FILTER (
            ALLSELECTED ( 'estate_data' ),
            'estate_data'[advert_number] = _seladvert
        )
    )
RETURN
    CALCULATE (
        MAX ( 'estate_data'[price] ),
        FILTER (
            ALLSELECTED ( 'estate_data' ),
            'estate_data'[advert_number] = _seladvert
                && 'estate_data'[data_download] = _mindate
        )
    )
Maxdate = 
VAR _seladvert =
    SELECTEDVALUE ( 'estate_data'[advert_number] )
VAR _maxdate =
    CALCULATE (
        MAX ( 'estate_data'[data_download] ),
        FILTER (
            ALLSELECTED ( 'estate_data' ),
            'estate_data'[advert_number] = _seladvert
        )
    )
RETURN
    CALCULATE (
        MAX ( 'estate_data'[price] ),
        FILTER (
            ALLSELECTED ( 'estate_data' ),
            'estate_data'[advert_number] = _seladvert
                && 'estate_data'[data_download] = _maxdate
        )
    )

yingyinr_0-1657185716220.png

If the above one can't help you get the desired result, please provide more sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community

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.

Helpful resources

Announcements
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

Check out the November 2023 Power BI update to learn about new features.

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Dashboard in a day with date

Exclusive opportunity for Women!

Join us for a free, hands-on Microsoft workshop led by women trainers for women where you will learn how to build a Dashboard in a Day!

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors