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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
trixie_dreadful
Microsoft Employee
Microsoft Employee

Getting date for max value

Hello!

 

I'm looking at COVID daily data. 

 

My main table looks like this:

dateRep

deaths

countriesAndTerritories

3/1/2020

1

Australia

3/1/2020

35

China

3/1/2020

9

Iran

3/1/2020

8

Italy

3/1/2020

2

Japan

3/1/2020

1

South_Korea

3/1/2020

1

United_States_of_America

3/2/2020

42

China

3/2/2020

11

Iran

 

I have created a second table for my consolidated deaths data, using GROUPBY

DeathsbyCountry = GROUPBY(data, data[continentExp],data[countriesAndTerritories], "TotalDeath", SUMX(CURRENTGROUP(),data[deaths]), "Max Death", MAXX(CURRENTGROUP(),data[deaths]))

 

This gives me the following:

 
 
data_continentExpdata_countriesAndTerritoriesTotalDeathMax Death
AmericaUnited_States_of_America1212284928
EuropeFrance297202004
AsiaIndia144762003
AmericaBrazil526451473
AsiaChina46401290
EuropeSpain283251179
EuropeUnited_Kingdom429271172
AmericaMexico233771091

 

Now, here's the BIG question - how do I find the date that is related to that Max Date?  

1 ACCEPTED SOLUTION

Hi @trixie_dreadful ,

 

We can create a calculate column in your calculate table.

 

Create a new column named MaxDeathDate in DeathsbyCountry table.

 

MaxDeathDate =
CALCULATE (
    MAX ( 'Table'[dateRep] ),
    FILTER (
        'Table',
        'Table'[countriesAndTerritories] = DeathsbyCountry[Table_countriesAndTerritories]
            && 'Table'[deaths] = DeathsbyCountry[Max Death]
    )
)

 

Getting1.jpg

 

If it doesn’t meet your requirement, could you please show the exact expected result based on the table that we have shared?

BTW, pbix as attached.

 

Best regards,

 

Community Support Team _ zhenbw

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
amitchandak
Super User
Super User

@trixie_dreadful , what is the objective of the second table?

 

Like I want last day of data then i would do like

new Table =
var _max = maxx(Table1,Table1[Date])
return 
calculate(Table, filter(Table,Table[Date]=_max))

 

The information you have provided is not making the problem clear to me. Can you please explain with an example.
Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.
Appreciate your Kudos.

Hi,

 

The first table (data) is the daily report of deaths by country:

Here is that example:

My main table looks like this (this is a truncated sample example).  The actual data is 25k rows.  

dateRep

deaths

countriesAndTerritories

3/1/2020

10

Australia

3/1/2020

35

China

3/1/2020

9

Iran

3/1/2020

8

Italy

3/1/2020

2

Japan

3/1/2020

1

South_Korea

3/1/2020

1

United_States_of_America

3/2/2020

3

Australia

3/2/2020

42

China

3/2/2020

11

Iran

3/2/2020

14

Italy

3/3/2020

4

United_States_of_America

 

The second table is to aggregate the COVID deaths by country, then return the date of the most deaths and the number of deaths on that day.  

Using the example data above,  the results would be:

countriesAndTerritoriesTotalDeathsMaxDeathsMaxDeathDate

Australia

13103/1/2020
China77423/2/2020
Iran993/1/2020
Italy22143/2/2020
Japan223/1/2020
South_Korea113/1/2020
United_States_of_America543/3/2020

 

The MaxDeathDate, isn't the most recent Date, its the date on which the MaxDeaths occured.  

 

Here's the expected result from the actual data:

data_countriesAndTerritoriesTotalDeathMaxDeathsMaxDeathsDate
United_States_of_America12122849284/16/2020
France2972020044/4/2020
India1447620036/17/2020

 

Its the column MaxDeathDate that I can't determine.

 

Hi @trixie_dreadful ,

 

We can create a calculate column in your calculate table.

 

Create a new column named MaxDeathDate in DeathsbyCountry table.

 

MaxDeathDate =
CALCULATE (
    MAX ( 'Table'[dateRep] ),
    FILTER (
        'Table',
        'Table'[countriesAndTerritories] = DeathsbyCountry[Table_countriesAndTerritories]
            && 'Table'[deaths] = DeathsbyCountry[Max Death]
    )
)

 

Getting1.jpg

 

If it doesn’t meet your requirement, could you please show the exact expected result based on the table that we have shared?

BTW, pbix as attached.

 

Best regards,

 

Community Support Team _ zhenbw

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

Helpful resources

Announcements
Sept PBI Carousel

Power BI Monthly Update - September 2024

Check out the September 2024 Power BI update to learn about new features.

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

Sept NL Carousel

Fabric Community Update - September 2024

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

Top Kudoed Authors