Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Sum (SKUs in two columns)

 

Background: 

Data table: EventID (Primekey) | Machines | Date/Time | Stage1 | Stage 2
Dim table: SKU Name | SKU ID 

 

Problem need help with: 

without having to unpivot the whole data table.  How can i find out the usage of each SKUs? (like the following) 

 

Ps: For every event, it could be a 1 or 2 stage , and any SKU can be used in either stages. 

  • hi  Anonymous 

    If you don't want to unpivot the whole data table. you could try this way as below:

    Create two inactive relationship between data table and dim table.

     

    Then create separate measure by userrelationship function as below:

    Stage1 = CALCULATE(COUNTA('Data table'[Stage1]),USERELATIONSHIP('Dim table'[SKU Name],'Data table'[Stage1]),'Data table'[Stage1]<>BLANK())
    
    Stage2 = CALCULATE(COUNTA('Data table'[Stage2]),USERELATIONSHIP('Dim table'[SKU Name],'Data table'[Stage2]),FILTER('Data table','Data table'[Stage2]<>BLANK()))
    
    Total = [Stage1]+[Stage2]

    Result:

    and here is sample pbix file, please try it.

     

    Regards,

    Lin

9 Replies

  • v-lili6-msft's avatar
    v-lili6-msft
    Icon for Community Support rankCommunity Support

    hi  Anonymous 

    If you don't want to unpivot the whole data table. you could try this way as below:

    Create two inactive relationship between data table and dim table.

     

    Then create separate measure by userrelationship function as below:

    Stage1 = CALCULATE(COUNTA('Data table'[Stage1]),USERELATIONSHIP('Dim table'[SKU Name],'Data table'[Stage1]),'Data table'[Stage1]<>BLANK())
    
    Stage2 = CALCULATE(COUNTA('Data table'[Stage2]),USERELATIONSHIP('Dim table'[SKU Name],'Data table'[Stage2]),FILTER('Data table','Data table'[Stage2]<>BLANK()))
    
    Total = [Stage1]+[Stage2]

    Result:

    and here is sample pbix file, please try it.

     

    Regards,

    Lin

  • VijayP's avatar
    VijayP
    Icon for Community Champion rankCommunity Champion

    Anonymous 

    Try creating a custom column in Power Query editor with Result you want!

    Let me know that is doable

    Regards

    Vijay Perepa

    • Anonymous's avatar
      Anonymous
      Not applicable

      VijayP 

      adding a column in the dim_product table ? how do i count Stage 1 and Stage 2 and the combo of them in the data table?

      • VijayP's avatar
        VijayP
        Icon for Community Champion rankCommunity Champion

        Anonymous  The way you have shown in the second picture. Else i need you to elaborate your question (rephrase your question)