Forum Discussion
Group By and Concatenate
Hello everyone,
I am trying to count the number of recurrences over weeks and also create a new column which concatenate the dates of the report when the data appeared.
From a fact table, I created a filter table:
From this new table, I used the GROUP BY function:
| KEY PO LINE | Date Cancellation Report |
| C0909 | 02/08/2019 |
| CR560 | 02/08/2019 |
| CE455 | 02/08/2019 |
| C0909 | 09/08/2019 |
| CR560 | 09/08/2019 |
| CF433 | 09/08/2019 |
| KEY PO LINE | RECURRENCE | Date Cancellation Report |
| C0909 | 2 | 02/08/2019 - 09/08/2019 |
| CR560 | 2 | 02/08/2019 - 09/08/2019 |
| CE455 | 1 | 02/08/2019 |
| CF433 | 1 | 09/08/2019 |
Thanks for your help!
Kind regards
Watou
11 Replies
- Greg_Deckler
Community Champion
For adding a concatenation column, just wrap your GROUPBY with an ADDCOLUMNS function.
- AnonymousNot applicable
Thanks for your reply. I am still novice in Power BI and cannot get what I want. I am getting several times the same data in the Concatenate while I would like only 1 data for each cancellation date. This is an example of what I got:
LINE
RECURRENCE Date Cancellation Report C0909 2 02/08/2019 - 02/08/2019 - 02/08/2019 - 02/08/2019 - 09/08/2019- 09/08/2019- 09/08/2019 I would like something similar to this:
LINE
RECURRENCE Date Cancellation Report C0909 2 02/08/2019 - 09/08/2019 Here is the formula I typed:
Group By Cancellation =ADDCOLUMNS(GROUPBY('Table Cancellation','Table Cancellation'[Key PO Line],"Count Recurrence",COUNTX(CURRENTGROUP(),count('Table Cancellation'[Key PO Line]))),"Concatenate",CONCATENATEX('Table Cancellation','Table Cancellation'[Date Cancellation Report],"-"))Thanks for your help,
- SteveCampbell
Memorable Member
Try:
Date Cancellation Report = VAR _Line = 'Outstanding PO Query'[KEY PO LINE] RETURN _LINE & IF ( 'Outstanding PO Query'[RECURRENCE] > 1, " - " & CALCULATE ( MAX ( 'Outstanding PO Query'[Date Cancellation Report] ), ALL ( 'Outstanding PO Query' ), 'Outstanding PO Query'[KEY PO LINE] = _VAR ), BLANK () )Love hearing about Power BI tips, jobs and news?
I love to share about these - connect with me!Stay up to date on
Read my blogs onRemember to spread knowledge in the community when you can!
- AnonymousNot applicable
Thanks Steve, however I am not sure to get it.
Should I do this calculation from the fact table? What will this give to me?
Sorry I am still novice in BI.
Thanks
- Ashish_Mathur
Super User
Hi,
Drag Key PO Line to the Row labels and write these measures:
=COUNTROWS(Data)
=MIN(Data[Date Cancellation Report])&if(MAX(Data[Date Cancellation Report])-MIN(Data[Date Cancellation Report])=0,BLANK()," - "&MAX(Data[Date Cancellation Report]))
Hope this helps.
- AnonymousNot applicable
Hi,
Thank you. Actually, the countrows does the job by counting the number of recurrences.
I used this Concatenate function as following
Concatenate = CONCATENATEX('Table Cancellation','Table Cancellation'[Date Cancellation Report],"- ",'Table Cancellation'[Key PO Line])I got this table:
Key PO Line Concatenate # Nb Lines C0225912 26/07/2019- 31/07/2019- 02/08/2019- 09/08/2019 4 C08322445 26/07/2019- 31/07/2019 2 I would like to show data in this table only when the latest date (for instance 09/08/2019 in this example) is included in the concatenate column.
Is it possible to go around with this with a measure or filter?
Thanks again,
- Ashish_Mathur
Super User
Hi,
I'm not sure of who you are replying to. Did you try out my solution?