Forum Discussion
Anonymous
5 years agoNot applicable
Max Date Count
Hello,
I am pretty new to power bi and would like to calculate the sum of the max date in the below table
| Product Id | Date |
| 1 | 7/21/2021 18:49 |
| 2 | 7/20/2021 18:49 |
| 3 | 7/19/2021 18:49 |
| 4 | 7/20/2021 18:49 |
| 5 | 7/21/2021 18:49 |
| 6 | 7/22/2021 18:49 |
| 7 | 7/22/2021 18:49 |
| 8 | 7/22/2021 18:49 |
| 9 | 7/22/2021 18:49 |
| 10 | 7/22/2021 18:49 |
In this case it is going to be 5. Could you please help me with the DAX.
Thanks
AD
4 Replies
- VahidDM
Super User
Hi Anonymous ,
First, you need to find the Max, so you can write the below code to find the Max :
VAR _MaxDate = MAX ( 'Product'[Date] )
then use this VAR to calculate the sum of the max date (Count):CALCULATE ( COUNTA ( 'Product'[Date] ), 'Product'[Date] = _MaxDate )So the Measure is as below:(make sure the table and column names are aligned with your file, then Copy and paste that on your file)Sum of the Max =VAR _MaxDate =MAX ( 'Product'[Date] )RETURNCALCULATE ( COUNTA ( 'Product'[Date] ), 'Product'[Date] = _MaxDate ) - Samarth_18
Community Champion
Hi Anonymous ,
You can try below code:-
count_of_dates = CALCULATE ( COUNT ( 'Product_data'[Date] ), LASTDATE('Product_data'[Date]) )output:-
Thanks
- AnonymousNot applicable
Thank you so much. That worked. One last question. if I use the similar table with few more information :
Product Date Name ADDRESS 1 7/21/2021 18:49 A abc 2 7/20/2021 18:49 B def 3 7/19/2021 18:49 C dhk 4 7/20/2021 18:49 D scj 5 7/21/2021 18:49 E sbn 6 7/22/2021 18:49 F sjx 7 7/22/2021 18:49 G scn 8 7/22/2021 18:49 H ivd 9 7/22/2021 18:49 I skl 10 7/22/2021 18:49 J kjs Now I want to create a table with product, name and address using the max date, how do I do that?
- Samarth_18
Community Champion
Hi Anonymous
You can directly drag your fields on table visual and take a latest of your date. PFB screenshot for reference:-
Note:- You can get latest option when you right click on Date in Values Pane