Forum Discussion

mbudiman's avatar
mbudiman
Helper III
1 year ago
Solved

Top N based on specific column in MATRIX table

hi, I want to show Top Product (by Sub Main Category) based on Net Revenue for Current Fiscal Quarter, and also shows corresponding Net Revenue for last 3 Fiscal Quarter. I use Matrix table and Top N function (top 50 by Net Revenue) for " Sub Main Category" in the Visual filter to achieve this.

 

Power BI calculate and sort Net Revenue based on Total Net Revenue for all Fiscal Quarter in the Matrix table. It shows Winter Jacket as top revenue. However, I want to show top revenue for current Fiscal Qtr (FY25Q2), where Summer Dress should be top revenue.

I have custom Fiscal Calendar table where Qtr_Seq_No = 0 means current Fiscal Qtr, Qtr_Seq_No = -1 means last Fiscal Qtr, Qtr_Seq_No = -2 means last 2 Fiscal Qtr, etc.

I have Sales Revenue table that contains column for Sub Main Category, FY_Fiscal_Qtr (field that link to Fiscal Calendar table), Net Revenue, Net Qty.

 

The following is what I want to achieve:

1. Sort Top Net Revenue for Sub Main Category for Qtr_Seq_No = 0.

2. Show Rank No for Sub Main Category for Qtr_Seq_No = 0

 

Pls advise how to achieve this. Thank you in advance.

 

 

 

 

  • Anonymous's avatar
    Anonymous
    1 year ago

    Hi mbudiman ,

     

    Please try code as below.

    New Net Revenue = 
    IF (
        HASONEVALUE ( 'Table'[FY_FISCAL_QTR] ),
        [Net Revenue],
        CALCULATE (
            [Net Revenue],
           FY_FISCAL_QTR,FY_FISCAL_QTR[QTR_SEQ_NO] = 0
        )
    )

    Result is as below.

     

    Best Regards,
    Rico Zhou

     

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

5 Replies

  • Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).

    Do not include sensitive information. Do not include anything that is unrelated to the issue or question.

    Need help uploading data? https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-p/963216

    Please show the expected outcome based on the sample data you provided.

    Want faster answers? https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi mbudiman ,

     

    According to your statement, I think you want to sort the category by the last FY_FISCAL_QTR. 

    As far as I know, when you sort the matrix by data in value field, Power BI will sort it by subtotal. 
    So I suggest you to try code as below to diy the subtotal for [Net Revenue].

    New Net Revenue =
    IF (
        HASONEVALUE ( 'Table'[FY_FISCAL_QTR] ),
        [Net Revenue],
        CALCULATE (
            [Net Revenue],
            'Table'[FY_FISCAL_QTR] = MAX ( DimDate[FY_FISCAL_QTR] )
        )
    )

    Result is as below.

     

    Best Regards,
    Rico Zhou

     

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

     

     

    • mbudiman's avatar
      mbudiman
      Helper III

      hi Rico,

      Thanks for providing solution. It almost achieve the desired result. However, my custom Financial Calendar table contains future fiscal Quarter too, so using MAX function to retrieve current Fiscal Qtr does not work.

      I need to retrieve current FIscal Qtr using condition Qtr_Seq_No = 0. Pls advise DAX statement to achieve this. 

       

      The following is the contain of FY_FISCAL_QTR table. Qtr_Seq_No = 0 means current Fiscal Qtr, Qtr_Seq_No = -1 means last Fiscal Qtr, Qtr_Seq_No = 1 means next future Fiscal Qtr.

      The colum Qtr Order is used for sorting FY_FISCAL_QTR in Matrix table.

       

      FY_FISCAL_QTRQTR_SEQ_NOQTR ORDER
      FY24Q1-5

      8

      FY24Q2-47
      FY24Q3-36
      FY24Q4-25
      FY25Q1-14
      FY25Q203
      FY25Q3-12
      FY25Q4-21

       

      Thank you in advance for your advise.

      • Anonymous's avatar
        Anonymous
        Not applicable

        Hi mbudiman ,

         

        Please try code as below.

        New Net Revenue = 
        IF (
            HASONEVALUE ( 'Table'[FY_FISCAL_QTR] ),
            [Net Revenue],
            CALCULATE (
                [Net Revenue],
               FY_FISCAL_QTR,FY_FISCAL_QTR[QTR_SEQ_NO] = 0
            )
        )

        Result is as below.

         

        Best Regards,
        Rico Zhou

         

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