Forum Discussion

seanpratt's avatar
seanpratt
Icon for Helper III rankHelper III
6 years ago
Solved

Only Showing Values in Table That Apply to both Row and Column

It's funny - I think I'm okay to Power BI until I have to do something I've never done before... hoping this is pretty easy.   I have a table that's just UserID, DateofVisit, AmountSpent.... that's...
  • edhans's avatar
    6 years ago

    See this PBIX for what I did.

     

    I created 2 calculated columns to get the visit and spend ranges:

     

     

    Spend Range = 
    VAR SpendRange =
        CALCULATE(
            SUM(Visits[Amount Spent]),
            ALLEXCEPT(Visits,Visits[User ID])
        )
    RETURN
    SWITCH(
        TRUE(),
        SpendRange >= 0 && SpendRange <= 1000, "0 - 1K",
        SpendRange >= 1001 && SpendRange <= 2000, ">1K - 2K",
        SpendRange >= 2001 && SpendRange <= 3000, ">2K - 3K",
        SpendRange > 3000, ">3K"
    )
    
    
    
    Visit Range = 
    VAR VisitCount =
        CALCULATE(
            COUNTROWS(Visits),
            ALLEXCEPT(Visits,Visits[User ID])
        )
    RETURN
    SWITCH(
        TRUE(),
        VisitCount >= 0 && VisitCount <= 3, "0 - 3",
        VisitCount >= 4 && VisitCount <= 6, "4 - 6",
        VisitCount >= 7 && VisitCount <= 0, "7 - 9"
    )

     

     

    Because the Spend Ranges will not sort properly, I created a new table in Power BI to just have the ranges and the sort priority:

    There was no need for the Visit ranges since as labeled, alphabetical sort would work. However, if you have visits above 9, you'd need to do the same type of table since 10 would sort before 4 alphabetically.

    Then in the model, I related this Range table to my data table.

     

     

    Added a sum measure:

     

     

    Total Spent = SUM(Visits[Amount Spent])

     

     

    Then dropped the fields in this matrix and told it to sort the Range by the Range Sort field in the Modeling tab.

     

    See Sort By Columns article for specifics on what I did there if you aren't aware of that feature.

    If I've not met your goal or you have questions, let me know!