Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

Problems creating a specific measure

Hello all,

 

I'm having some difficulties to implment a measure or a workaround to do the following:

I need to implement a stacked bar chart to see the "Executed Quantity Batch by Operator".

In the axis I have the operator but my problem is to create a measure to calculate the rest.

 

In sql I have the following table (the data is not complete, it's just for the example):

IdDimVoiceOperator_idDimStartDate_idBatchNumberFactTaskExecution_id
117943908/07/202162717
117944908/07/202162717
118016908/07/202122774
118017908/07/202112774
118018908/07/202122774
118158908/07/202112787
118159908/07/202112787
118160908/07/202112787
118161908/07/202112787
118204908/07/202112802
118205908/07/202112802
118206908/07/202112802

 

And in my sql query I have the following which gives me the expected result:

select sum(batch) from (
select count(distinct(batchnumber)) as batch
FROM [Sonae.Voice.202x].[dbo].[FactTaskDetailExecution]
where DimStartDate_id = '2021-07-08' and DimVoiceOperator_id = 9
group by FactTaskExecution_id) as total

 

The where clause I have the operator in the Axis of the chart and the date is in a slicer so I just need to understand how to apply the sum, the count and the group by.

 

Can anyone have some tips on this?

 

Best regards,

Rui Santos

  • Hi Anonymous 

     

    What you need is a Sumx of the Distinct count, forgive the bad measure name

    sumx distinct count = SUMX(VALUES('Table'[FactTaskExecution_id]), [Distinct Batch Count])

    Again pbix sample attached

     

     

     

9 Replies

  • richbenmintz's avatar
    richbenmintz
    Resident Rockstar

    Hi Anonymous,

     

    Can you provide an expected outcome for you visual please?

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hello richbenmintz ,

       

      Thanks for you quick reply.

      Yes, looking at that data the result should be:

      • 1 distinct for FactTaskExecution_id = 2717
      • 2 disctinct for FactTaskExecution_id = 2774
      • 1 distinct for FactTaskExecution_id = 2787
      • 1 distinct for FactTaskExecution_id = 2802

      So the final result should be the sum of the above values which is 5.

       

      Regards,

      Rui

  • richbenmintz's avatar
    richbenmintz
    Resident Rockstar

    Hi Anonymous,

     

    Making some assumptions on the Visual requirement, the following measure provides the distinct count of Batches

    Distinct Batch Count = DISTINCTCOUNT('Table'[BatchNumber])

    Resulting in the following visual

    Attached please find a simple sample file

    Thanks,

    • Anonymous's avatar
      Anonymous
      Not applicable

      richbenmintz 

       

      Thanks, it's almost there. I just need to group by the FactTaskExecution_id becaus if batchnumber = 1 in two different FactTaskExecution_id it should count as well if you know what I mean.

       

      Thank you.

      Rui

      • richbenmintz's avatar
        richbenmintz
        Resident Rockstar

        Hi Anonymous 

         

        What you need is a Sumx of the Distinct count, forgive the bad measure name

        sumx distinct count = SUMX(VALUES('Table'[FactTaskExecution_id]), [Distinct Batch Count])

        Again pbix sample attached

         

         

         

  • DemoFour's avatar
    DemoFour
    Continued Contributor

    Hi Anonymous 

     

    Can you confirm this data table is right and what it is you want to achive please. 

     

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hello, DemoFour 

       

      I want to show in one stack bar chart the Executed Batches By Operator. Looking at the data the expected result should be:

      • 1 distinct for FactTaskExecution_id = 2717
      • 2 disctinct for FactTaskExecution_id = 2774
      • 1 distinct for FactTaskExecution_id = 2787
      • 1 distinct for FactTaskExecution_id = 2802

      So the final result should be the sum of the above values which is 5.

       

      However using just the distinctcount is not enough because different FactTaskExecution_id can have the same batchnumber and I want the sum of them. Don't know if you understand..

       

      Thanks,

      Rui