Forum Discussion

harshadrokade's avatar
harshadrokade
Post Partisan
1 month ago
Solved

Showing Prev Qtr data in matrix visual

Hi All,


I have a table as Fact Sales. I have a Dim Date table (MIS date column) which is connected with MIS date column from Fact Sales.

I have created a matrix visual as below-
Rows- ID, Name
Columns- Sales Qtr (Quarterly dates)
Value-Sum of Sales Amount
Slicer on page- MIS date from Dim date table (Quarterly dates)

In Matrix visual, I want to show previous qtr Sales amount if a qtr doesnt have Sales amount. E.g. For ID-ID1, Name-A1, for Mar25 Sales date, for Sep23 Sales Qtr doesnt have Sales amount and so I want to show Jun23 Qtr Sales amount for Sep23 i.e. 1027. When the Sales amount is not there for a Sales Qtr of A ID and Name, that Sales qtr row doesnt exist in data. Refer below data for for Sep23 which is not there in base data as Sales amount is not there. And still I want to show the prev Sales qtr's Sales amount in matrix, for tht missing Qtr date.

Request you to Provide a soluton for the same.

Data-

NameIDSales QtrMIS DateSales Amount
A1ID16/30/20223/31/2025706
A1ID19/30/20223/31/2025869
A1ID112/31/20223/31/2025486
A1ID13/31/20233/31/20251664
A1ID16/30/20233/31/20251027
A1ID112/31/20233/31/20251685
A1ID13/31/20243/31/20251582
A1ID16/30/20243/31/20251248
A1ID19/30/20243/31/2025981
A1ID112/31/20243/31/2025301
A1ID13/31/20253/31/2025751
A1ID16/30/20226/30/2025947
A1ID19/30/20226/30/2025973
A1ID16/30/20236/30/20251016
A1ID19/30/20236/30/2025769
A1ID112/31/20236/30/2025842
A1ID13/31/20246/30/20251223
A1ID16/30/20246/30/20251076
A1ID19/30/20246/30/20251573
A1ID112/31/20246/30/20251615
A1ID13/31/20256/30/2025306
A1ID16/30/20256/30/2025984
A1ID16/30/20229/30/2025504
A1ID19/30/20229/30/2025874
A1ID112/31/20229/30/20251412
A1ID13/31/20239/30/20251656
A1ID16/30/20239/30/20251093
A1ID19/30/20239/30/2025631
A1ID112/31/20239/30/2025749
A1ID13/31/20249/30/2025664
A1ID16/30/20249/30/2025151
A1ID19/30/20249/30/20251784
A1ID112/31/20249/30/2025701
A1ID13/31/20259/30/20251636
A1ID16/30/20259/30/2025256
A1ID19/30/20259/30/20251184
A2ID29/30/20223/31/20251445
A2ID212/31/20223/31/2025495
A2ID23/31/20233/31/20251913
A2ID26/30/20233/31/20251404
A2ID29/30/20233/31/20251154
A2ID212/31/20233/31/2025401
A2ID23/31/20243/31/2025487
A2ID26/30/20243/31/2025569
A2ID29/30/20243/31/20251776
A2ID212/31/20243/31/2025259
A2ID23/31/20253/31/2025211
A2ID212/31/20226/30/20251569
A2ID23/31/20236/30/2025774
A2ID26/30/20236/30/2025925
A2ID29/30/20236/30/20251046
A2ID212/31/20236/30/2025443
A2ID23/31/20246/30/20251135
A2ID26/30/20246/30/2025160
A2ID29/30/20246/30/2025724
A2ID212/31/20246/30/20251647
A2ID23/31/20256/30/20251239
A2ID26/30/20256/30/20251552
A2ID26/30/20229/30/2025988
A2ID29/30/20229/30/20251831
A2ID212/31/20229/30/2025476
A2ID23/31/20239/30/20251885
A2ID26/30/20239/30/2025666
A2ID29/30/20239/30/20251827
A2ID212/31/20239/30/20251817
A2ID23/31/20249/30/20251668
A2ID26/30/20249/30/20251558
A2ID29/30/20249/30/2025625
A2ID212/31/20249/30/20251864
A2ID23/31/20259/30/2025162
A2ID26/30/20259/30/2025409
A2ID29/30/20259/30/20251193
A3ID26/30/20223/31/2025928
A3ID29/30/20223/31/2025273
A3ID212/31/20223/31/20251249
A3ID212/31/20233/31/2025980
A3ID23/31/20243/31/20251595
A3ID26/30/20243/31/20251095
A3ID212/31/20243/31/20251353
A3ID23/31/20253/31/2025373
A3ID26/30/20226/30/20251063
A3ID23/31/20236/30/20251365
A3ID26/30/20236/30/20251160
A3ID29/30/20236/30/2025635
A3ID212/31/20236/30/20251468
A3ID23/31/20246/30/20251654
A3ID26/30/20246/30/20251247
A3ID29/30/20246/30/2025800
A3ID212/31/20246/30/20251031
A3ID23/31/20256/30/2025930
A3ID26/30/20256/30/20251569
A3ID26/30/20229/30/20251954
A3ID29/30/20229/30/2025463
A3ID212/31/20229/30/2025770
A3ID23/31/20239/30/20251324
A3ID26/30/20239/30/2025434
A3ID29/30/20239/30/20251847
A3ID212/31/20239/30/2025663
A3ID23/31/20249/30/2025964
A3ID26/30/20249/30/2025692
A3ID29/30/20249/30/2025181
A3ID212/31/20249/30/20251812
A3ID23/31/20259/30/2025818
A3ID26/30/20259/30/20251771
A3ID29/30/20259/30/20251413

 

  • harshadrokade 

    in your sample data, I found the value for A1 in 2023 3rd Q

     

    then i delete thses two rows

     

    you can create a dim table and create a measure

    Measure =
    VAR CurrQtr = SELECTEDVALUE('Table 2'[Sales Qtr])
    VAR CurrVal =
        CALCULATE(
            SUM('Table'[Sales Amount])
        )
    VAR PrevVal =
        CALCULATE(
            SUM('Table'[Sales Amount]),
            REMOVEFILTERS('Table 2'),
            'Table 2'[Sales Qtr] = EOMONTH(CurrQtr, -3)
        )
    RETURN
        COALESCE(CurrVal, PrevVal)
     
     
    pls see the attachment below

7 Replies

  • Kagiyama_yutaka's avatar
    Kagiyama_yutaka
    Continued Contributor

    To place the DimDate quarter on the matrix Columns so that all quarters appear, including those with no FactSales rows. Then use a DAX measure that returns the sales for the selected quarter, or when FactSales has no row for that quarter the sales of the previous quarter.

  • Hi,

    Create an inactive relationship between the Sales Qtr column and the Date column of the Calendar table.  Write these measures

    Sales = sum(Data[Sales amount])

    Sales in PQ = calculate([Sales],previousquarter(Calendar[Date]),userelationship(Data[Sales qtr],Calendar[Date]))

    Hope this helps.

  • harshadrokade 

    in your sample data, I found the value for A1 in 2023 3rd Q

     

    then i delete thses two rows

     

    you can create a dim table and create a measure

    Measure =
    VAR CurrQtr = SELECTEDVALUE('Table 2'[Sales Qtr])
    VAR CurrVal =
        CALCULATE(
            SUM('Table'[Sales Amount])
        )
    VAR PrevVal =
        CALCULATE(
            SUM('Table'[Sales Amount]),
            REMOVEFILTERS('Table 2'),
            'Table 2'[Sales Qtr] = EOMONTH(CurrQtr, -3)
        )
    RETURN
        COALESCE(CurrVal, PrevVal)
     
     
    pls see the attachment below
  • harshadrokade 

     

    Create a measure and use it in the matrix instead of the raw Sales Amount column:

     

    Sales Amount (Prev Qtr Fallback) =
    VAR CurrentQtr = MAX('Fact Sales'[Sales Qtr])
    VAR ActualAmount = SUM('Fact Sales'[Sales Amount])
    VAR PrevAvailableQtr =
    CALCULATE(
    MAX('Fact Sales'[Sales Qtr]),
    FILTER(
    ALL('Fact Sales'[Sales Qtr]),
    'Fact Sales'[Sales Qtr] < CurrentQtr
    )
    )
    VAR PrevQtrAmount =
    CALCULATE(
    SUM('Fact Sales'[Sales Amount]),
    ALL('Fact Sales'[Sales Qtr]),
    'Fact Sales'[Sales Qtr] = PrevAvailableQtr
    )
    RETURN
    IF(ISBLANK(ActualAmount), PrevQtrAmount, ActualAmount)

    If this answer helped, please click 👍 or Accept as Solution.
    -Kedar
    LinkedIn: https://www.linkedin.com/in/kedar-pande

  • ShahRukhSameer's avatar
    ShahRukhSameer
    Responsive Resident

    Hi harshadrokade,

     

    Since the missing quarter doesn't exist as a row in your fact table, a regular SUM(Sales Amount) won't be able to return anything for that quarter. What you need is a carry-forward measure that returns the most recent available Sales Amount for the same ID/Name whenever the current quarter is missing.

     

    The first thing I'd check is that your Matrix is using the Quarter from your Date table and that "Show items with no data" is enabled. Otherwise, Power BI won't even display the missing quarter.

     

    Then, instead of using a simple sum measure, try creating a measure that returns the last non-blank value:

     

    Sales Amount Carry Forward =

    VAR CurrentQtr = MAX('Dim Date'[MIS Date])

    VAR LastQtrWithData = CALCULATE( MAX('Fact Sales'[Sales Qtr]), FILTER( ALL('Fact Sales'[Sales Qtr]), 'Fact Sales'[Sales Qtr] <= CurrentQtr && NOT ISBLANK( CALCULATE(SUM('Fact Sales'[Sales Amount])) ) ) )

     

    RETURN CALCULATE( SUM('Fact Sales'[Sales Amount]), 'Fact Sales'[Sales Qtr] = LastQtrWithData )

     

    For example, for A1 / ID1 with MIS Date = 31-Mar-2025:

    Jun-23 = 1027

    Sep-23 = Missing

     

    The measure would return 1027 for Sep-23 by carrying forward the last available quarter's value.

     

    This is usually the approach taken when the requirement is "show the previous quarter's value if the current quarter has no data." The important part is having a complete Date table driving the Matrix columns so that the missing quarters are still displayed even when no fact row exists for that period.