Forum Discussion

JemmaD's avatar
JemmaD
Icon for Helper V rankHelper V
1 year ago
Solved

Grouping rows in a table based on a matching value

I have a model which has a policy dimension (distinct policy reference) linked to two fact tables - 'Policy' and 'Location' Both Policy and Location tables have multiple rows per policy reference, a...
  • OwenAuger's avatar
    OwenAuger
    1 year ago

    Thanks for the update JemmaD !

    The POLICYREFERENCE values are sorted in the visual in lexicographic order which the ROWNUMBER function should also be using, so it is odd that the colours are not as expected!

     

    Idea #1:

    Could you try creating this Policy Index Debug measure and adding it to the table visual:

    Policy Index Debug =
    IF (
        NOT ISEMPTY ( 'Policy' ) || NOT ISEMPTY ( 'Location' ),
        VAR _PolicyVisible =
            CALCULATETABLE (
                DISTINCT (
                    UNION (
                        SUMMARIZE ( 'Policy', 'Dim Policy'[POLICYREFERENCE] ),
                        SUMMARIZE ( 'Location', 'Dim Policy'[POLICYREFERENCE] )
                    )
                ),
                ALLSELECTED ()
            )
        VAR _PolicyIndex =
            ROWNUMBER ( _PolicyVisible, ORDERBY ( 'Dim Policy'[POLICYREFERENCE], ASC ) )
        RETURN
            _PolicyIndex
    )

     This should return the index that is being used to determine the colour, so should help figure out where it's going wrong! The first POLICYREFERENCE should correspond to 1, then next to 2, and so on.

     

    The ISEMPTY tests are there so that the index is only returned for existing rows of the visual where either fact table is nonempty (hopefully).

     

    Other ideas:

    • The bidirectional relationships could be causing an issue of some sort. Do they need to be bidirectional or could they be converted to single directional?
    • Could you share a PBIX (dummy data if needed) and I could try to debug at my end.

    All the best