Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Split Column without Duplicates

Hi,

I'm pretty new to PowerBI so any help would be appreciated. I have a dataset (called 'Asset Reg') coming from a Sharepoint list which gives me the below data.

Id

Vendor

Dept

4

Google

Dept1, Dept2, Dept4

19

Amazon

Dept2

103

Facebook

Dept3

501

LinkedIn

Dept4, Dept1, Dept3, Dept2

23

Oracle

Dept1

I want to do 2 main things with this:

  1. I want to filter on Dept without the commas. For instance, If I create a slicer and select Dept 2, then Google, Amazon & LinkedIn should show up. 
  2. I want to show which vendors are 'shared' across departments. essentially anything with more than 1 dept is shared. Google & LinkedIn are shared while Amazon, Facebook & Oracle are not. 

 What I did: I split the columns by comma delimiter to identify the individual dept (this worked perfectly). Next, I wanted to find the 'shared' vendors. To do this, I used the below calculated column to say any column with the ID listed more than once is ‘shared’

 Shared=

IF (

COUNTROWS ( FILTER ('Asset Reg', 'Asset Reg'[Id] = EARLIER ( 'Asset Reg'[Id] ) ) )

> 1,

"Shared Vendor",

"Not Shared"

)

 This gives me the following output in powerbi:

 Id

Vendor

Dept

Shared

4

Google

Dept1

Shared Asset

4

Google

Dept2

Shared Asset

4

Google

Dept4

Shared Asset

19

Amazon

Dept 2

Not Shared

103

Facebook

Dept3

Not Shared

501

LinkedIn

Dept4

Shared Asset

501

LinkedIn

Dept1

Shared Asset

501

LinkedIn

Dept3

Shared Asset

501

LinkedIn

Dept2

Shared Asset

23

Oracle

Dept1

Not Shared

 My only thing is, if I create a visual on the Shared column, my numbers will be inflated. I tried to search for dax measures that would only count the first occurrence of a duplicate (by ID #) and ignore the others. So using the example above, Google should be listed as ‘shared’ once for Dept1 and the subsequent Google entries (Dept2, Dept4) should be ignored. Same for LinkedIn.

I also tried to duplicate the table and group by ID and delete the duplicates but the calculated column changed to 'not shared' for every vendor listed.

Any help would be appreciated!

  • Hi Anonymous ,

     

    we can try to add a calculated column to meet your requirement:

     

    Shared = 
    IF (
        CALCULATE (
            DISTINCTCOUNT ( 'Asset Reg'[Dept] ),
            FILTER ( 'Asset Reg', 'Asset Reg'[Id] = EARLIER ( 'Asset Reg'[Id] ) )
        ) > 1,
        IF (
            [Dept]
                = CALCULATE (
                    MIN ( 'Asset Reg'[Dept] ),
                    FILTER ( 'Asset Reg', 'Asset Reg'[Id] = EARLIER ( 'Asset Reg'[Id] ) )
                ),
            "Shared Asset",
            BLANK ()
        ),
        "Not Shared"
    )

     

     


    Best regards,

     

6 Replies

  • VasTg's avatar
    VasTg
    Memorable Member

    Anonymous 

     

    I would use the below M query to get the number of departments and use the value to divide the sales(or any summation measures) before pivoting the Dept column

     

    Custom=List.Count(Text.Split([Dept],","))

     

    IDVendorDeptSalesCustomSales/Custom
    4GoogleDept1, Dept2, Dept4103 
    19AmazonDept2201 
    103FacebookDept3301 
    501LinkedInDept4, Dept1, Dept3, Dept2404 
    23OracleDept1501 

     

     

    You could also use distinct count in the visual for any count measures.

     

    If you don't want to pivot the table, you could use the below query to get True/False (Replace True with Shared and False with "Not shared").

     

    Custom.1=Text.Contains([Dept], ",")

    Or a simple conditional column => If  Custom  = 1 "Not Shared" else "Shared"

     

    IDVendorDeptSalesCustomCustom.1
    4GoogleDept1, Dept2, Dept4103TRUE
    19AmazonDept2201FALSE
    103FacebookDept3301FALSE
    501LinkedInDept4, Dept1, Dept3, Dept2404TRUE
    23OracleDept1501FALSE

     

    After that you could split the Dept column and Pivot the table. The only advantage in pivoting the table is when you use Dept as a slicer, it will show individual departments intead of  all the departments for ID, Vendor combination.

     

    If this helps, mark it as a solution

    Kudos are nice too.

     

  • Hi,

    Based on the input data you have shared in the first table, show the exact result that you are expecting.

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi  thanks for responding.

       

      The desired outcome would be a slicer with:

      Dept 1

      Dept 2

      Dept 3

      Dept 4

       

      So if I selected Dept 2, all vendors that belonged to Dept 2 would show up in my data. Which i'm able to achieve via 'split to row' option in Powerbi.

       

      I would like an output that looks similar to the below:

       

       

       Id

      Vendor

      Dept

      Shared

      4

      Google

      Dept1

      Shared Asset

      4

      Google

      Dept2

       

      4

      Google

      Dept4

       

      19

      Amazon

      Dept 2

      Not Shared

      103

      Facebook

      Dept3

      Not Shared

      501

      LinkedIn

      Dept4

      Shared Asset

      501

      LinkedIn

      Dept1

       

      501

      LinkedIn

      Dept3

       

      501

      LinkedIn

      Dept2

       

      23

      Oracle

      Dept1

      Not Shared

       

       

       

       

       

      The main thing i'm trying to determine is what vendors are being used by 1 department (not shared) vs vendors being used by multiple departments(shared). The only way I can think to do this would be to tell PowerBi "any vendor that has more than 1 department is a shared service". and I just need the first occurrence flagged so that I don't have duplicates. I don't want my numbers to inflate because a vendor with 3 departments will show up 3x. I tried using distinct count and the numbers still weren't right.

      I'm open to a different approach if there is one that makes more sense/easier. I hope I cleared that up and I appreciate your help. Please let me know if you need more detail.

       

      • v-lid-msft's avatar
        v-lid-msft
        Community Support

        Hi Anonymous ,

         

        we can try to add a calculated column to meet your requirement:

         

        Shared = 
        IF (
            CALCULATE (
                DISTINCTCOUNT ( 'Asset Reg'[Dept] ),
                FILTER ( 'Asset Reg', 'Asset Reg'[Id] = EARLIER ( 'Asset Reg'[Id] ) )
            ) > 1,
            IF (
                [Dept]
                    = CALCULATE (
                        MIN ( 'Asset Reg'[Dept] ),
                        FILTER ( 'Asset Reg', 'Asset Reg'[Id] = EARLIER ( 'Asset Reg'[Id] ) )
                    ),
                "Shared Asset",
                BLANK ()
            ),
            "Not Shared"
        )

         

         


        Best regards,