Forum Discussion

wongzqn's avatar
wongzqn
Frequent Visitor
6 years ago
Solved

CountRows of Matrix Visualization with values from a Measure

Hello, I have this matrix visualization below, corporate donor name from table 1, year 2017-2020 from table 2, and the values (donor status) as a measure to categorize the donor status.  

 

The ultimate goal is to calculate the number of 'new', 'lapsed', 'recurring', 'lost', 'recovered' (values) for each year to do a YoY analysis. Currently met with difficulty to countrows on measure. 

 

Not sure and 

 

Appreciate your help! 

 

 

 

 

  • Hi wongzqn,

     

    Please refer to the steps:

     

    1. Create a status table by enter data:

    Then create a calculated table:

     

    Donor Status year = CROSSJOIN(VALUES('Status'[Donor Status]),VALUES(_Calendar[Year]))

     

     

    Then you can use the following measure to count values:

     

    Measure =
    VAR t =
        SUMMARIZE (
            CROSSJOIN ( VALUES ( CombinedData[Donor Name] ), VALUES ( _Calendar[Year] ) ),
            CombinedData[Donor Name],
            _Calendar[Year],
            "status", [Donor Status]
        )
    RETURN
        COUNTX (
            FILTER (
                t,
                [Year] = MAX ( 'Donor Status year'[Year] )
                    && [status] = MAX ( 'Donor Status year'[Donor Status] )
            ),
            [Donor Name]
        ) + 0

     

    For more details, please refer to pbix file:  https://qiuyunus-my.sharepoint.com/personal/pbipro_qiuyunus_onmicrosoft_com/_layouts/15/onedrive.aspx

     

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

     

    Best Regards,

    Dedmon Dai

     

5 Replies

  • wongzqn ,  The information you have provided is not making the problem clear to me. Can you please explain with an example.
    Can you share sample data and sample output in table format?

     

    Please refer these three


    https://blog.enterprisedna.co/new-vs-existing-customers-advanced-analytics-w-dax/
    https://www.sqlbi.com/articles/computing-new-customers-in-dax/

    https://community.powerbi.com/t5/Desktop/Churn-Rate-lost-Customer/m-p/1173754#M529196


    Appreciate your Kudos.


    • wongzqn's avatar
      wongzqn
      Frequent Visitor

      Hi amitchandak, thanks for reverting!

       

      Sample data:

       

      Donor NameDonation ValueDonation Date
      DonorA5009 Sep 2018
      DonorB10008 Dec 2018
      DonorA10007 Mar 2019

       

      Sample Output:

      Donor StatusYearCount
      New

      2017

      10
      Lost20177
      Recurring20179
      Recovered201710
      Lasped201743
      New

      2018

      15
      Lost201812
      Recurring20188
      Recovered201811
      Lasped201845
      New

      2019

      20
      Lost201915
      Recurring201916
      Recovered201915
      Lasped201947

       

       

      The value of 'Donor Status' is a measure where I categorize and label based on date and donation:

       

      2.9 Donor Status =


      VAR ThisYearDonations =
      CALCULATE(SUM(CombinedData[Donation Cash Value]), DATESYTD(_Calendar[Date]))


      VAR LastYearDonations =
      CALCULATE(SUM(CombinedData[Donation Cash Value]), PREVIOUSYEAR(_Calendar[Date]))


      VAR PriorYearsDonations =
      CALCULATE(SUM(CombinedData[Donation Cash Value]),
             FILTER(
                 ALL(_Calendar[Date]),
                 YEAR(_Calendar[Date]) < YEAR(MAX(_Calendar[Date]))-1
               )
      )

       

       

      RETURN
            IF(AND(ThisYearDonations = 0 && LastYearDonations = 0, PriorYearsDonations > 0), "Lost",
                    (IF(AND(ThisYearDonations= 0 && LastYearDonations = 0, PriorYearsDonations = 0), "NA",
                    (IF(AND(ThisYearDonations = 0, LastYearDonations > 0), "Lapsed",
                    (IF(AND(ThisYearDonations > 0, LastYearDonations > 0), "Recurring",
                    (IF(AND(ThisYearDonations > 0 && LastYearDonations = 0, PriorYearsDonations > 0), "Recovered",
                  (IF(AND(ThisYearDonations > 0 && LastYearDonations = 0, PriorYearsDonations = 0), "New", BLANK())))))))))))

       

       

      • v-deddai1-msft's avatar
        v-deddai1-msft
        Community Support

        Hi wongzqn,

         

        Please refer to the steps:

         

        1. Create a status table by enter data:

        Then create a calculated table:

         

        Donor Status year = CROSSJOIN(VALUES('Status'[Donor Status]),VALUES(_Calendar[Year]))

         

         

        Then you can use the following measure to count values:

         

        Measure =
        VAR t =
            SUMMARIZE (
                CROSSJOIN ( VALUES ( CombinedData[Donor Name] ), VALUES ( _Calendar[Year] ) ),
                CombinedData[Donor Name],
                _Calendar[Year],
                "status", [Donor Status]
            )
        RETURN
            COUNTX (
                FILTER (
                    t,
                    [Year] = MAX ( 'Donor Status year'[Year] )
                        && [status] = MAX ( 'Donor Status year'[Donor Status] )
                ),
                [Donor Name]
            ) + 0

         

        For more details, please refer to pbix file:  https://qiuyunus-my.sharepoint.com/personal/pbipro_qiuyunus_onmicrosoft_com/_layouts/15/onedrive.aspx

         

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

         

        Best Regards,

        Dedmon Dai

         

  • Greg_Deckler's avatar
    Greg_Deckler
    Community Champion

    Not really enough information to go on, please first check if your issue is a common issue listed here: https://community.powerbi.com/t5/Community-Blog/Before-You-Post-Read-This/ba-p/1116882

    Also, please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

    The most important parts are:
    1. Sample data as text, use the table tool in the editing bar
    2. Expected output from sample data
    3. Explanation in words of how to get from 1. to 2.