Forum Discussion

Jadegirlify's avatar
Jadegirlify
Helper I
2 years ago

Calculated Column based on Totals from Values

I need to create columns showing total count of work locations by department. I would like to have this output table below:

Original Table

DepartmentWork Location
HROnsite
HROnsite
HROnsite
HROnsite
Claims Onsite
Claims Virtual
UnderwritingOnsite
UnderwritingOnsite
UnderwritingVirtual
UnderwritingVirtual
UnderwritingVirtual
OperationsVirtual
OperationsVirtual

 

 

Result Table (Note: Total HR count is 4 and all 4 are onsite, that's why virtual is 0 etc)

DepartmentTotal DepartmentWork LocationOnsiteVirtualTotal
HR13Onsite404
HR13Onsite404
HR13Onsite404
HR13Onsite404
Claims 13Onsite102
Claims 13Virtual012
Underwriting13Onsite205
Underwriting13Onsite205
Underwriting13Virtual035
Underwriting13Virtual035
Underwriting13Virtual035
Operations13Virtual022
Operations13Virtual022

 

Any assistance will be greatly appreciated. 

6 Replies

  • Hi Jadegirlify ,

     Do you need this to be a calculated column? You could try using a Matrix visual and putting the DepartmentWorkLocation field in the columns field.

    • Jadegirlify's avatar
      Jadegirlify
      Helper I

      Hi, it can be a matrix, i tried to do a matrix but the columns still weren't coming up right.

    • Jadegirlify's avatar
      Jadegirlify
      Helper I

      djurecic It didn't work with a Matrix, I was getting 1 in each row as on the Total Department column as the values for Onsite, Virtual and Total were also not accurate

  • Ok. Can you post screenshots of what you did and the result?

  • Anonymous's avatar
    Anonymous
    Not applicable

    Thanks djurecic  for his prompt reply.
    Hi Jadegirlify ,
    Based on the information you provided, you should use ALL to filter filters. You can modify your measures like below:

    total all = 
    CALCULATE ( COUNTROWS ( 'Table' ), ALL ( 'Table' ) )
    
    LocationOnsite = 
    VAR _department =
        SELECTEDVALUE ( 'Table'[Department] )
    VAR _work_location =
        SELECTEDVALUE ( 'Table'[Work Location] )
    VAR _count_onsite =
        CALCULATE (
            COUNTROWS ( 'Table' ),
            FILTER (
                ALL ( 'Table' ),
                'Table'[Department] = _department
                    && 'Table'[Work Location] = _work_location
            )
        )
    RETURN
        IF ( _work_location = "Onsite", _count_onsite, 0 )
    
    Virtual = 
    VAR _department =
        SELECTEDVALUE ( 'Table'[Department] )
    VAR _work_location =
        SELECTEDVALUE ( 'Table'[Work Location] )
    VAR _count_virtual =
        CALCULATE (
            COUNTROWS ( 'Table' ),
            FILTER (
                ALL ( 'Table' ),
                'Table'[Department] = _department
                    && 'Table'[Work Location] = "Virtual"
            )
        )
    RETURN
        IF ( _work_location = "Virtual", _count_virtual, 0 )
    
    Total = 
    VAR _department =
        SELECTEDVALUE ( 'Table'[Department] )
    RETURN
        CALCULATE (
            COUNTROWS ( 'Table' ),
            FILTER ( ALL ( 'Table' ), 'Table'[Department] = _department )
        )
    

    Final output:

    How to Get Your Question Answered Quickly - Microsoft Fabric Community

    If it does not help, please provide more details with your desired out put and pbix file without privacy information.

     

    Best Regards,

    Ada Wang

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

    • Jadegirlify's avatar
      Jadegirlify
      Helper I

      Anonymous Thank you! I'm getting "Visual has exceeded available resources" error. Not sure if it's because the real data I'm working with has about 15k of rows and I'm supposed to be filtering only 49 rows from the data. I tried to create an index row as well, but the result table isn't showing an index row in chronological order-- like the one you created. But I understand t's because the original table you started with is 13 rows and the result table is 13 rows.

      In a situation where the original table has thousands of row, how can be use an index column to show a result table of 13 with index table numbered from 1-13 instead of random numbers between 1 to 10s of thousands. Does that make any sense to you? See screenshot of my index. Could that be the reason why the measures you created in giving me an error?