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

Combine multiple rows and show as comma separated and sum up values

Hello,

I have a bit challenging requirement as described below. Below is sample of data that I have.

 

File namePolicyStart dateEnd DateAmt

A

a101-01-202001-01-2021100
Aa201-01-202001-01-2021200
Aa301-01-202001-01-2021300
Aa404-04-202003-04-2021400
Aa506-03-201905-03-2020500
Bb125-05-201924-05-2020600
Bb217-06-202016-06-2021700

 

I have 2 filters - File name and Policy.

When I select File name - "A",  and Policy a1,a2,a3, I should get the below output.

File NameA
Policya1,a2,a3
Amt600

 

As you can see from the above output Amt of policies a1,a2,a3 have summed up and total is shown as 600 and three policies have been shown as comma seperated.

But the logic to be applied here is that start date and end date of all the policies should be same, only then summation will happen.In this case a1,a2,a3 had same start and end date. If instead of a1,a2,a3 I select a1,a2,a4 although a1,a2 has same dates but a4 has different date and hence it should show either blank/ or some error message / or some pop up.

 

So basically, when I select 1 filename and then when I select multiple policies, if start and end date is same for all the policies should get sum of amt and show policies as comma seperated. If any policy has different start and end date, then no values should be shown.

 

Is it possible to achieve this in Power BI.

 

Regards,

Amit Darak

1 ACCEPTED SOLUTION
Icey
Community Support
Community Support

Hi @Anonymous ,

 

Please check if this could meet your requirements:

Policy Measure = 
VAR t =
    FILTER (
        ADDCOLUMNS (
            'Table',
            "Count_",
                COUNTROWS (
                    FILTER (
                        'Table',
                        'Table'[File name] = EARLIER ( 'Table'[File name] )
                            && 'Table'[Policy] <= EARLIER ( 'Table'[Policy] )
                            && 'Table'[Start date] = EARLIER ( 'Table'[Start date] )
                            && 'Table'[End Date] = EARLIER ( 'Table'[End Date] )
                    )
                ),
            "Countrows_runningtotal",
                COUNTROWS (
                    FILTER (
                        'Table',
                        'Table'[File name] = EARLIER ( 'Table'[File name] )
                            && 'Table'[Policy] <= EARLIER ( 'Table'[Policy] )
                    )
                )
        ),
        [Count_] = [Countrows_runningtotal]
    )
RETURN
    IF (
        COUNTROWS ( t ) = COUNTROWS ( ALLSELECTED ( 'Table'[Policy] ) ),
        CONCATENATEX ( t, [Policy], ", " )
    )
Amt Measure = 
VAR t =
    FILTER (
        ADDCOLUMNS (
            'Table',
            "Count_",
                COUNTROWS (
                    FILTER (
                        'Table',
                        'Table'[File name] = EARLIER ( 'Table'[File name] )
                            && 'Table'[Policy] <= EARLIER ( 'Table'[Policy] )
                            && 'Table'[Start date] = EARLIER ( 'Table'[Start date] )
                            && 'Table'[End Date] = EARLIER ( 'Table'[End Date] )
                    )
                ),
            "Countrows_runningtotal",
                COUNTROWS (
                    FILTER (
                        'Table',
                        'Table'[File name] = EARLIER ( 'Table'[File name] )
                            && 'Table'[Policy] <= EARLIER ( 'Table'[Policy] )
                    )
                )
        ),
        [Count_] = [Countrows_runningtotal]
    )
RETURN
    IF (
        COUNTROWS ( t ) = COUNTROWS ( ALLSELECTED ( 'Table'[Policy] ) ),
        SUMX ( t, [Amt] )
    )

 

policy.gif

 

 

Best Regards,

Icey

 

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

View solution in original post

3 REPLIES 3
Icey
Community Support
Community Support

Hi @Anonymous ,

 

Please check if this could meet your requirements:

Policy Measure = 
VAR t =
    FILTER (
        ADDCOLUMNS (
            'Table',
            "Count_",
                COUNTROWS (
                    FILTER (
                        'Table',
                        'Table'[File name] = EARLIER ( 'Table'[File name] )
                            && 'Table'[Policy] <= EARLIER ( 'Table'[Policy] )
                            && 'Table'[Start date] = EARLIER ( 'Table'[Start date] )
                            && 'Table'[End Date] = EARLIER ( 'Table'[End Date] )
                    )
                ),
            "Countrows_runningtotal",
                COUNTROWS (
                    FILTER (
                        'Table',
                        'Table'[File name] = EARLIER ( 'Table'[File name] )
                            && 'Table'[Policy] <= EARLIER ( 'Table'[Policy] )
                    )
                )
        ),
        [Count_] = [Countrows_runningtotal]
    )
RETURN
    IF (
        COUNTROWS ( t ) = COUNTROWS ( ALLSELECTED ( 'Table'[Policy] ) ),
        CONCATENATEX ( t, [Policy], ", " )
    )
Amt Measure = 
VAR t =
    FILTER (
        ADDCOLUMNS (
            'Table',
            "Count_",
                COUNTROWS (
                    FILTER (
                        'Table',
                        'Table'[File name] = EARLIER ( 'Table'[File name] )
                            && 'Table'[Policy] <= EARLIER ( 'Table'[Policy] )
                            && 'Table'[Start date] = EARLIER ( 'Table'[Start date] )
                            && 'Table'[End Date] = EARLIER ( 'Table'[End Date] )
                    )
                ),
            "Countrows_runningtotal",
                COUNTROWS (
                    FILTER (
                        'Table',
                        'Table'[File name] = EARLIER ( 'Table'[File name] )
                            && 'Table'[Policy] <= EARLIER ( 'Table'[Policy] )
                    )
                )
        ),
        [Count_] = [Countrows_runningtotal]
    )
RETURN
    IF (
        COUNTROWS ( t ) = COUNTROWS ( ALLSELECTED ( 'Table'[Policy] ) ),
        SUMX ( t, [Amt] )
    )

 

policy.gif

 

 

Best Regards,

Icey

 

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 , Create measures like

Policies = concatenatex(Table,Table[Policy],",")

Amt Measure = Sum(Table[Amt])

 

Use Matrix with file name on column and measure in values

and use Show On row

https://www.burningsuit.co.uk/blog/2019/04/7-secrets-of-the-matrix-visual/

 

Anonymous
Not applicable

Hi Amit,

 

The challenging part of the problem is how to compare if start and end date are the same for all policies and sum up only those policies where start and end date is same. If the dates are different, value should not add up and not display anything.

 

Regards,

Amit Darak

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.