Forum Discussion
Show last data for each date
- 4 years ago
Hi, EdisonTrent
First you need to pivot column like this:
Then you can create a new table and then create two columns to display what you want.
like this:
new table:
Table 2 = VAR Datelist = CALENDAR ( MIN ( 'Table'[Datefact] ), MAX ( 'Table'[Datefact] ) ) RETURN ADDCOLUMNS ( Datelist, "New York", VAR a = MAXX ( FILTER ( ALL ( 'Table' ), [Datefact] <= [Date] && [New York] <> BLANK () ), [Datefact] ) RETURN MAXX ( FILTER ( ALL ( 'Table' ), [Datefact] = a ), [New York] ), "London", VAR a = MAXX ( FILTER ( ALL ( 'Table' ), [Datefact] <= [Date] && [London] <> BLANK () ), [Datefact] ) RETURN MAXX ( FILTER ( ALL ( 'Table' ), [Datefact] = a ), [London] ) )new column:
Total = VAR CurNewYork = [New York] VAR CurLondon = [London] VAR LastNewYork = MAXX ( FILTER ( ALL ( 'Table 2' ), [Date] = EARLIER ( 'Table 2'[Date] ) - 1 ), [New York] ) VAR LastLondon = MAXX ( FILTER ( 'Table 2', [Date] = EARLIER ( 'Table 2'[Date] ) - 1 ), [London] ) RETURN SWITCH ( TRUE (), LastNewYork = BLANK () || ( LastNewYork = [New York] && LastLondon = [London] ) || LastNewYork <> [New York] && LastLondon <> [London], [New York] + [London], LastNewYork <> [New York] && LastLondon = [London], [New York] + LastLondon, LastNewYork = [New York] && LastLondon <> [London], LastNewYork + [London] )Total2 = VAR CurNewYork = [New York] VAR CurLondon = [London] VAR LastNewYork = MAXX ( FILTER ( ALL ( 'Table 2' ), [Date] = EARLIER ( 'Table 2'[Date] ) - 1 ), [New York] ) VAR LastLondon = MAXX ( FILTER ( 'Table 2', [Date] = EARLIER ( 'Table 2'[Date] ) - 1 ), [London] ) RETURN SWITCH ( TRUE (), LastNewYork = BLANK () || LastNewYork <> [New York] && LastLondon <> [London], [New York] + [London], LastNewYork <> [New York] && LastLondon = [London], [New York], LastNewYork = [New York] && LastLondon <> [London], [London] )Did I answer your question? Please mark my reply as solution. Thank you very much.
If not, please feel free to ask me.Best Regards,
Community Support Team _Janey
I would like to reword my question:
What if I had 100 cities and new city can appear any time in the data?
Hi, EdisonTrent
Obviously not, it can't have the exact same result you want.
It's very troublesome, you need to create a date table, establish relationship, and then write measure...
and that table visual is not available, maybe it can be displayed with matrix visual. In short, it is very complicated, mainly because your needs are not suitable for calculation on powerbi.
Best Regards,
Community Support Team _Janey