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.
Hello,
I have a question if you are able to help with it. I have the following table of dates against user_ids (these will be updating frequently about 20,000 records):
TABLE A:
----------------------
date user_id
20/02/2016 A
22/02/2016 C
27/02/2016 D
04/03/2016 C
06/03/2016 C
01/04/2016 C
01/04/2016 A
30/04/2016 B
05/05/2016 C
06/05/2016 B
26/05/2016 A
01/06/2016 B
01/09/2016 C
I'd like to add another column to this same table which counts the total dates that exist between the date of the current record less 2 months for each user_id. E.g. for the value against the date 05/05/2016 for user_id C - it should count the total dates in the table between 05/03/2016 to 05/05/2016 that also have a user_id of C- so it would show 3 - as the following dates fall within this range:
06/03/2016 C
01/04/2016 C
05/05/2016 C
hope that makes senses?
Using my sample data - the final table should look as follows:
TABLE A:
----------------------
date user_id total dates less 2 months by user
20/02/2016 A 1
22/02/2016 C 1
27/02/2016 D 1
04/03/2016 C 2
06/03/2016 C 3
01/04/2016 C 4
01/04/2016 A 2
30/04/2016 B 1
05/05/2016 C 3
06/05/2016 B 2
26/05/2016 A 2
01/06/2016 B 3
01/09/2016 C 1
If you are able to help with this it would be most appreciated!
many thanks
Solved! Go to Solution.
Hi,
Please try this column
Column = VAR CurrentDate = Table1[date ] VAR TwoMonthsbefore = DATE ( YEAR ( CurrentDate ), MONTH ( CurrentDate ) - 2, DAY ( CurrentDate ) ) RETURN CALCULATE ( COUNTROWS ( Table1 ), FILTER ( ALLEXCEPT ( Table1, Table1[user_id ] ), Table1[date ] <= CurrentDate && Table1[date ] >= TwoMonthsbefore ) )
Hi @domdom,
Could you please mark the proper answers as solutions?
Best Regards,
Dale
Hi,
Please try this column
Column = VAR CurrentDate = Table1[date ] VAR TwoMonthsbefore = DATE ( YEAR ( CurrentDate ), MONTH ( CurrentDate ) - 2, DAY ( CurrentDate ) ) RETURN CALCULATE ( COUNTROWS ( Table1 ), FILTER ( ALLEXCEPT ( Table1, Table1[user_id ] ), Table1[date ] <= CurrentDate && Table1[date ] >= TwoMonthsbefore ) )
pbix file attached as well
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
97 | |
97 | |
82 | |
75 | |
66 |
User | Count |
---|---|
126 | |
105 | |
103 | |
81 | |
72 |