Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

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.

Reply
Anonymous
Not applicable

Any idea on processing lists, that have variabe number of items for filtering or grouping.

 

Hi all,

I have a List with a variable number of items (8-9 items, where each item is a word or short phrase) in a dimention:

A , B
A
B, C
A, C

 

I would like to be able to Group:

A3
B2
C2

 

or Filter:

ADimention Row 1 Details & associated Fact rows
BDimention Row 1 Details & associated Fact rows
ADimention Row 2 Details & associated Fact rows

 

I have tried a couple of methods...
The best Idea I could think of was, was to use a checksum like fuction to create an index & snowflake the model design. But I couldn't find a string to number function that would achieve this easily.

The only idea i have left,
is to use the list.contains and creat a bunch of new columns, but that hard codes the items and adds lots of empty fields.

Any Ideas would be great?



p.s. sorry i originally had a lot more context, particulary all the ideas I tried but PBI lost the content :(.

 

----

Notes: I realise some of what I wrote above may have been a bit confusing. I was after the abillity to visually slice and dice by filtering to create groups etc. The asnwer provided below does do this well enough, it enables filtering of the dimenion and the count per item.   I could not get it to also filter the fact table but I'm ok with that for this current need.

 

 

1 ACCEPTED SOLUTION
smpa01
Super User
Super User

@Anonymous  you can write a single DAX measure

Measure =
VAR _0 =
    ADDCOLUMNS ( dim, "new", SUBSTITUTE ( dim[entries], ",", "|" ) )
VAR _1 =
    GENERATE (
        _0,
        ADDCOLUMNS (
            GENERATESERIES ( 1, PATHLENGTH ( [new] ) ),
            "seperateValue", PATHITEM ( [new], [value], TEXT )
        )
    )
VAR _2 =
    ADDCOLUMNS (
        'Table',
        "@count",
            COUNTX (
                FILTER ( _1, [seperateValue] = EARLIER ( 'Table'[Column1] ) ),
                [seperateValue]
            )
    )
RETURN
    SUMX ( _2, [@count] )

 

smpa01_0-1635195416349.png

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

View solution in original post

4 REPLIES 4
smpa01
Super User
Super User

@Anonymous  you can write a single DAX measure

Measure =
VAR _0 =
    ADDCOLUMNS ( dim, "new", SUBSTITUTE ( dim[entries], ",", "|" ) )
VAR _1 =
    GENERATE (
        _0,
        ADDCOLUMNS (
            GENERATESERIES ( 1, PATHLENGTH ( [new] ) ),
            "seperateValue", PATHITEM ( [new], [value], TEXT )
        )
    )
VAR _2 =
    ADDCOLUMNS (
        'Table',
        "@count",
            COUNTX (
                FILTER ( _1, [seperateValue] = EARLIER ( 'Table'[Column1] ) ),
                [seperateValue]
            )
    )
RETURN
    SUMX ( _2, [@count] )

 

smpa01_0-1635195416349.png

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs
Anonymous
Not applicable

@smpa01this works both for grouping as you show and for filtering rows in the dimention.

To enable the filtering on the rows, simply add the measure to the table/visual with the a "filter on this visual" where "Measure is not blank".  Although this only seems to work with data from the dimenion table.

For others trying this, the code won't work if null is an options, so you wil have to replace them with a meaful text value.

 

 

 

v-yanjiang-msft
Community Support
Community Support

Hi @Anonymous 

Here's my solution.

Method1

1, Split column by delimiter.

vkalyjmsft_0-1635156075402.png

2, Copy column1.2 to a new table.

vkalyjmsft_1-1635156100245.png

 

vkalyjmsft_2-1635156100248.png

 

3, Append column1.1 and the copied new column.

vkalyjmsft_3-1635156100250.png

After append, it shows like bellow:

<![if !vml]>

vkalyjmsft_4-1635156124250.png

 

<![endif]>

4, Do not select “null” value.

<![if !vml]>

vkalyjmsft_5-1635156124251.png

 

<![endif]>

5, Use group by count function to column1.1

<![if !vml]>

vkalyjmsft_6-1635156124252.png

 

<![endif]>

Then it becomes like this:

<![if !vml]>

vkalyjmsft_7-1635156124252.png

 

<![endif]>

Method2

1, Split column by delimiter.

<![if !vml]>

vkalyjmsft_8-1635156164963.png

 

<![endif]>

2.Create a new table

<![if !vml]>

vkalyjmsft_9-1635156164963.png

 

<![endif]>

3.Create a new measure for the result.

<![if !vml]>

vkalyjmsft_10-1635156164965.png

 

<![endif]>

Best Regards,
Community Support Team _ kalyj


If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

amitchandak
Super User
Super User

@Anonymous , In power query Split by delimiters  and then group with count

Split Column Power Query: https://youtu.be/FyO9Vmhcfag

 

group by

https://docs.microsoft.com/en-us/power-query/group-by

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.