Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
Hi,
I would like to create a column (RESULT) with the condition that if the category is repeated sequentially (ID) it returns the first ID.
For example:
Solved! Go to Solution.
Hi,
Thank you for your clarification.
Please check the below picture and the attached pbix file.
Result First ID CC =
VAR _currentid = Data[ID]
VAR _condition =
ADDCOLUMNS (
Data,
"@condition",
VAR _currentid = Data[ID]
VAR _currentrow = Data[Category]
VAR _prevrow =
MAXX (
OFFSET ( -1, Data, ORDERBY ( Data[ID], ASC ),,, MATCHBY ( Data[ID] ) ),
Data[Category]
)
RETURN
IF ( _currentrow = _prevrow || BLANK (), 0, 1 )
)
VAR _partition =
ADDCOLUMNS (
_condition,
"@partition", SUMX ( FILTER ( _condition, Data[ID] <= EARLIER ( Data[ID] ) ), [@condition] )
)
VAR _currentpartition =
MINX ( FILTER ( _partition, Data[ID] = _currentid ), [@partition] )
RETURN
MINX ( FILTER ( _partition, [@partition] = _currentpartition ), Data[ID] )
Hi,
Please check the below picture and the attached pbix file.
It is for creating a new column.
Result First ID CC =
MINX ( FILTER ( Data, Data[Category] = EARLIER ( Data[Category] ) ), Data[ID] )
Hi,
Thank you for your clarification.
Please check the below picture and the attached pbix file.
Result First ID CC =
VAR _currentid = Data[ID]
VAR _condition =
ADDCOLUMNS (
Data,
"@condition",
VAR _currentid = Data[ID]
VAR _currentrow = Data[Category]
VAR _prevrow =
MAXX (
OFFSET ( -1, Data, ORDERBY ( Data[ID], ASC ),,, MATCHBY ( Data[ID] ) ),
Data[Category]
)
RETURN
IF ( _currentrow = _prevrow || BLANK (), 0, 1 )
)
VAR _partition =
ADDCOLUMNS (
_condition,
"@partition", SUMX ( FILTER ( _condition, Data[ID] <= EARLIER ( Data[ID] ) ), [@condition] )
)
VAR _currentpartition =
MINX ( FILTER ( _partition, Data[ID] = _currentid ), [@partition] )
RETURN
MINX ( FILTER ( _partition, [@partition] = _currentpartition ), Data[ID] )
User | Count |
---|---|
22 | |
11 | |
8 | |
6 | |
6 |
User | Count |
---|---|
26 | |
13 | |
11 | |
9 | |
6 |