The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
I have a sample like this table. The column count of 2 is the output I expect. With the same ID, order Date ascending. We count number 2 (or rank) by Date. If the value in column A is 1, we break the loop and count (or rank) the number 2 again from the beginning.
Plz help me. Thank you
Solved! Go to Solution.
Hi Phuonghm22,
Please follow these steps:
(1) Create a calculated column to count
Co2 =
VAR _date =
CALCULATE (
MAX ( 'Table'[Date] ),
FILTER (
ALL ( 'Table' ),
'Table'[A] <> 2
&& 'Table'[Date] <= EARLIER ( 'Table'[Date] )
&& 'Table'[ID] = EARLIER ( 'Table'[ID] )
)
)
VAR _count =
CALCULATE (
COUNTROWS ( 'Table' ),
FILTER (
ALL ( 'Table' ),
'Table'[Date] <= EARLIER ( 'Table'[Date] )
&& 'Table'[Date] > _date
&& 'Table'[ID] = EARLIER ( 'Table'[ID] )
)
) + 0
RETURN
_count
(2) Final output
Best Regards,
Gallen Luo
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi Phuonghm22,
Please follow these steps:
(1) Create a calculated column to count
Co2 =
VAR _date =
CALCULATE (
MAX ( 'Table'[Date] ),
FILTER (
ALL ( 'Table' ),
'Table'[A] <> 2
&& 'Table'[Date] <= EARLIER ( 'Table'[Date] )
&& 'Table'[ID] = EARLIER ( 'Table'[ID] )
)
)
VAR _count =
CALCULATE (
COUNTROWS ( 'Table' ),
FILTER (
ALL ( 'Table' ),
'Table'[Date] <= EARLIER ( 'Table'[Date] )
&& 'Table'[Date] > _date
&& 'Table'[ID] = EARLIER ( 'Table'[ID] )
)
) + 0
RETURN
_count
(2) Final output
Best Regards,
Gallen Luo
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Thank you so much
User | Count |
---|---|
11 | |
8 | |
6 | |
6 | |
6 |
User | Count |
---|---|
23 | |
14 | |
13 | |
10 | |
8 |