Forum Discussion

gjurcin_cch's avatar
gjurcin_cch
Frequent Visitor
3 years ago
Solved

How to sum a string in matrix as zero value

I have one compex DAX where one division needs to happen and get three different kind of results:

1. if the division is equal to 1 the result needs to be "No data in Lake"

2. if the result have zero denominator then result is "No data in BW"

3. otherwise I want to have regular result

 

Here is the DAX

CALCULATE
(
    IF
    (
        SUMX
        (
            'metadata_data_quality reconcile_status_v1',
            'metadata_data_quality reconcile_status_v1'[kbi_difference]/ABS('metadata_data_quality reconcile_status_v1'[expected_value])
        ) == 1,
        "No data in Lake",
        IF
        (
            ISERROR
            (
                SUMX
                (
                    'metadata_data_quality reconcile_status_v1',
                    'metadata_data_quality reconcile_status_v1'[kbi_difference]/ABS('metadata_data_quality reconcile_status_v1'[expected_value])
                )
            ),
            "No data in BW",
            SUMX
            (
                'metadata_data_quality reconcile_status_v1',
                'metadata_data_quality reconcile_status_v1'[kbi_difference]/ABS('metadata_data_quality reconcile_status_v1'[expected_value])
            )
        )
    ),

    FILTER
    (
        'metadata_data_quality reconcile_status_v1',
        'metadata_data_quality reconcile_status_v1'[process_run_id] == 'metadata_data_quality reconcile_status_v1'[last_process_run_id]
    )
)

 

The formula is working fine but the issue is coming when the matrix is created. Check the image bellow:

 

 

How can I make subtotal to be zero result if I have more then one values in the columns? Like in the case that I have for "No data in BW". Check the image bellow

 

 

 

Or even better how can be strings threated as zero value in subtotals and while collapsing the matrix rows?

 

Thank you in advance!

 

 

 

 

  • tamerj1 I have tried with it seems to be very close but now the filter does not take any actions and not working on the context. Can you explain me the meaning of hasonevalue so I can somehow design the dax on my own?

     

    SWITCH
    (
        TRUE (),
        ISERROR ( ratio ), "No data in BW",
        ratio = 1, "No data in Lake",
        HASONEVALUE ('metadata_data_quality reconcile_status_v1'[fiscper]), ratio,
        "No data in Lake"
    )

     

5 Replies

  • tamerj1's avatar
    tamerj1
    Community Champion

    Hi gjurcin_cch 

    To be honest, I don't fully understand the requirement. However, I may advise to simplify the measure as follows

    =
    VAR Result =
    SUMX (
    FILTER (
    'metadata_data_quality reconcile_status_v1',
    'metadata_data_quality reconcile_status_v1'[process_run_id] = 'metadata_data_quality reconcile_status_v1'[last_process_run_id]
    ),
    'metadata_data_quality reconcile_status_v1'[kbi_difference]
    / ABS ( 'metadata_data_quality reconcile_status_v1'[expected_value] )
    )
    RETURN
    SWITCH (
    TRUE (),
    ISERROR ( Result ), "No data in BW",
    Result = 1, "No data in Lake",
    Result
    )

    • gjurcin_cch's avatar
      gjurcin_cch
      Frequent Visitor

      Hi, tamerj1 thanks for the optimization of the formula it pretty much better than the previous one. But lets get back to the requirement and try to simplify.

       

      This is what I have now.

      data_lake_object_idexpected_kbi_providerexpected_kbi_namepartition_levelprocess_run_id202100020210202022020Grand Total
      cch_bw.mtc.ca_red07_m.v1CA_Q_D_CA_RED07M_Q07ktotalfac0403-RU20230125_003231_4898235_68697  00
         0410-AM20230125_000338_4037250_19423  00
         0415-LV20230125_001908_2470907_24425  00
         0416-EE20230125_001051_6220341_63416No data in LakeNo data in LakeNo data in Lake3
         0417-LT20230125_001812_9030151_77396 No data in LakeNo data in Lake2
         0428-BG20230125_000641_7936029_15792  No data in LakeNo data in Lake
         0430-MK20230125_002029_2134199_19551  00
         0440-RS20230125_002426_3454789_62214  00
         0450-GR20230125_001155_1327277_95418  00
         0470-NG20230125_002126_8875583_13205  00
         0480-GB20230125_001557_2587576_42395  00

       

      But I want to have the result below.

       

      data_lake_object_idexpected_kbi_providerexpected_kbi_namepartition_levelprocess_run_id202100020210202022020Grand Total
      cch_bw.mtc.ca_red07_m.v1CA_Q_D_CA_RED07M_Q07ktotalfac0403-RU20230125_003231_4898235_68697  00
         0410-AM20230125_000338_4037250_19423  00
         0415-LV20230125_001908_2470907_24425  00
         0416-EE20230125_001051_6220341_63416No data in LakeNo data in LakeNo data in Lake0
         0417-LT20230125_001812_9030151_77396 No data in LakeNo data in Lake0
         0428-BG20230125_000641_7936029_15792  No data in LakeNo data in Lake
         0430-MK20230125_002029_2134199_19551  00
         0440-RS20230125_002426_3454789_62214  00
         0450-GR20230125_001155_1327277_95418  00
         0470-NG20230125_002126_8875583_13205  00
         0480-GB20230125_001557_2587576_42395  00

       

  • tamerj1's avatar
    tamerj1
    Community Champion

    gjurcin_cch 

    Please try

    =
    VAR Result =
    SUMX (
    FILTER (
    'metadata_data_quality reconcile_status_v1',
    'metadata_data_quality reconcile_status_v1'[process_run_id] = 'metadata_data_quality reconcile_status_v1'[last_process_run_id]
    ),
    'metadata_data_quality reconcile_status_v1'[kbi_difference]
    / ABS ( 'metadata_data_quality reconcile_status_v1'[expected_value] )
    )
    RETURN
    SWITCH (
    TRUE (),
    ISERROR ( Result ), "No data in BW",
    Result = 1, "No data in Lake",
    HASONEVALUE ( [YearMonth] ), Result,
    "No data in Lake"
    )

    • gjurcin_cch's avatar
      gjurcin_cch
      Frequent Visitor

      tamerj1 I have tried with it seems to be very close but now the filter does not take any actions and not working on the context. Can you explain me the meaning of hasonevalue so I can somehow design the dax on my own?

       

      SWITCH
      (
          TRUE (),
          ISERROR ( ratio ), "No data in BW",
          ratio = 1, "No data in Lake",
          HASONEVALUE ('metadata_data_quality reconcile_status_v1'[fiscper]), ratio,
          "No data in Lake"
      )

       

      • tamerj1's avatar
        tamerj1
        Community Champion

        gjurcin_cch 

        What do you mean by "the filter does not take any actions and not working on the context"?

         

        HASONEVALUE checks if the column referred to in its argument has only one value in the current filter context. Basically, for the [fiscper] shall have multiple values in the total column which represents an aggregation of multiple months. Can be also replace with ISINSCOPE that shall act the same in this situation.