Microsoft Fabric Community Conference 2025, March 31 - April 2, Las Vegas, Nevada. Use code FABINSIDER for a $400 discount.
Register nowThe Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.
I am having data as per the below table
Product | Date | Category |
Alpha | 25-02-2023 | Service |
Alpha | 17-02-2023 | Service |
Alpha | 06-02-2023 | Purchase |
Beta | 05-02-2023 | Purchase |
Beta | 25-02-2023 | Service |
Gama | 22-02-2023 | Service |
Gama | 16-02-2023 | Service |
Gama | 21-01-2023 | Purchase |
Gama | 17-02-2023 | Service |
I want to add one column in the last as shown below with the name "New Category"
Please suggest how to create this column.
Product | Date | Category | New Category |
Alpha | 25-02-2023 | Service | Service_2 |
Alpha | 17-02-2023 | Service | Service_1 |
Alpha | 06-02-2023 | Purchase | Purchase |
Beta | 05-02-2023 | Purchase | Purchase |
Beta | 25-02-2023 | Service | Service_1 |
Gama | 22-02-2023 | Service | Service_3 |
Gama | 16-02-2023 | Service | Service_1 |
Gama | 21-01-2023 | Purchase | Purchase |
Gama | 17-02-2023 | Service | Service_2 |
please try
New category =
VAR CurrentDate = 'Table'[Date]
VAR T1 =
CALCULATETABLE (
'Table',
ALLEXCEPT ( 'Table', 'Table'[Product], 'Table'[Category] )
)
VAR Check =
COUNTROWS ( T1 ) > 1
VAR T2 =
ADDCOLUMNS (
T,
"NewCat",
[Category] & "_"
& IF ( Check, RANKX ( T1, [Date],, asc, DENSE ) )
)
RETURN
MAXX ( FILTER ( T2, [Date] = CurrentDate ), [NewCat] )
you may also try to add a column like:
Column =
VAR _table =
FILTER(
TableName,
TableName[Product]=EARLIER(TableName[Product])
&&TableName[Category]=EARLIER(TableName[Category])
)
VAR _index = RANKX(_table, [Date],,ASC)
RETURN
IF(
COUNTROWS( _table)=1,
[Category],
[Category]&"_"&_index
)
it worked like:
Hi,
Please check the below picture and the attached pbix file.
New Category CC =
SWITCH (
TRUE (),
Data[Category] = "Purchase", Data[Category],
Data[Category] = "Service",
Data[Category] & "_"
& COUNTROWS (
WINDOW (
1,
ABS,
0,
REL,
SUMMARIZE (
FILTER ( Data, Data[Category] = "Service" ),
Data[Product],
Data[Date]
),
ORDERBY ( Data[Date], ASC ),
KEEP,
PARTITIONBY ( Data[Product] )
)
)
)
If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.
Thanks
but i am getting this output with your query
Product | Date | Category | New Category |
Alpha | 25-02-2023 | Service | Service_1 |
Alpha | 17-02-2023 | Service | Service_1 |
Alpha | 06-02-2023 | Purchase | Purchase |
Beta | 05-02-2023 | Purchase | Purchase |
Beta | 25-02-2023 | Service | Service_1 |
Gama | 22-02-2023 | Service | Service_1 |
Gama | 16-02-2023 | Service | Service_1 |
Gama | 21-01-2023 | Purchase | Purchase |
Gama | 17-02-2023 | Service | Service_1 |
Output is not unique...
Product | Date | Category | New Category |
Delta | 17-02-23 | Puchase | Purchase |
Delta | 05-02-23 | Service | Service_1 |
Delta | 06-02-23 | Service | Service_1 |
Delta | 16-02-23 | Service | Sercvice_3 |
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Check out the February 2025 Power BI update to learn about new features.
User | Count |
---|---|
25 | |
12 | |
9 | |
9 | |
9 |
User | Count |
---|---|
21 | |
14 | |
14 | |
13 | |
13 |