Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Venkatesh_
Frequent Visitor

Need help in dax while using matrix visual - Row total is not giving me the correct result


Can anyone of you help me to figure out why my subtotals are not populating here please? If i add the all selected to the product level still it end up giving me the wrong result in matrix visual. Please let me know if you need any more information. Thanks!

In matrix I have product level on top and the site names are at the sublevel in matrix rows.

Predicted Year Income 1 =
CALCULATE(
    COUNT(BITransactions[Shopping List Tranasaction_FK]),
    DISTINCT(BITransactions[Shopping List Tranasaction_FK]),
    DATESINPERIOD(Calendar[Date], MAX(Calendar[Date]), -7, DAY)
) * 52 * ROUND(
    CALCULATE(
        AVERAGE('BITransactions'[Price])
    ),
    2
)

Predicted Year Income 2 =   CALCULATE(
    COUNT(BITransactions[Shopping List Tranasaction_FK]),
    DISTINCT(BITransactions[Shopping List Tranasaction_FK]),
    DATESINPERIOD(
        Calendar[Date],
        MAX(Calendar[Date]),
        -7,
        DAY
    )
) * 52 * ROUND(
    CALCULATE(
        AVERAGE('BITransactions'[Price]),
        ALLSELECTED(Sites[Name])
    ),
    2
)

Proj. Annual Var =

VAR PYI1 = [Predicted Year Income 1]

VAR PYI2 = [Predicted Year Income 2]

VAR Result = PYI1 - PYI2

RETURN Result


Variance of Avg Sell Price =

VAR AvgPrice = ROUND(AVERAGEX(BITransactions,'BITransactions'[Price]), 2)

VAR OtherAvg = ROUND(CALCULATE(
        AVERAGEX(BITransactions,'BITransactions'[Price]),
        ALLSELECTED('Sites'[Name])), 2)

VAR Result = AvgPrice - OtherAvg

RETURN
IF(AvgPrice = BLANK(),BLANK(),Result)


Venkatesh__0-1717756084533.png

 

1 ACCEPTED SOLUTION

@v-kaiyue-msft   Thanks for your reply. Still, your measure is missing overall total row value. Here is the correct measure which helps me to acheieve desired result

Proj. Annual Var =
VAR PYI1 = [Predicted Year Income 1]
VAR PYI2 = [Predicted Year Income 2]

VAR Result =
    IF(
        ISINSCOPE(Sites[Name]) && ISINSCOPE(BITransactions[ProductName]),
        PYI1 - PYI2,
        SUMX(
            SUMMARIZE(
                BITransactions,
                Sites[Name],
                BITransactions[ProductName],
                "Diff", [Predicted Year Income 1] - [Predicted Year Income 2]
            ),
            [Diff]
        )
    )

RETURN Result

  

View solution in original post

11 REPLIES 11
v-kaiyue-msft
Community Support
Community Support

Hi @Venkatesh_ ,

 

You can try this.

Measure 4 = 
var _table1=
DISTINCT('BITransactions'[ProductName])
var _table2=
DISTINCT('Sites'[Name])
var _table3=
CROSSJOIN(
    _table1,_table2)
var _table4=
ADDCOLUMNS(
    _table3,"1",[Predicted Year Income 1],
    "2",[Predicted Year Income 2])
var _table5=
ADDCOLUMNS(
    _table4,"3",[1] - [2])
var _value=
SUMX(
    FILTER(
        _table5,[ProductName]=MAX('BITransactions'[ProductName])),[3])
return
IF(
    HASONEVALUE(
        'Sites'[Name]),[Proj. Annual Var],
    IF(
        HASONEVALUE(BITransactions[ProductName]),_value))

vkaiyuemsft_0-1718963849475.png

 

Best Regards,

Clara Gong

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

@v-kaiyue-msft   Thanks for your reply. Still, your measure is missing overall total row value. Here is the correct measure which helps me to acheieve desired result

Proj. Annual Var =
VAR PYI1 = [Predicted Year Income 1]
VAR PYI2 = [Predicted Year Income 2]

VAR Result =
    IF(
        ISINSCOPE(Sites[Name]) && ISINSCOPE(BITransactions[ProductName]),
        PYI1 - PYI2,
        SUMX(
            SUMMARIZE(
                BITransactions,
                Sites[Name],
                BITransactions[ProductName],
                "Diff", [Predicted Year Income 1] - [Predicted Year Income 2]
            ),
            [Diff]
        )
    )

RETURN Result

  

v-kaiyue-msft
Community Support
Community Support

Hi @Venkatesh_ ,

 

Thanks for the reply from @fahadqadir3 , please allow me to provide another insight: 

 

It seems that it may be a problem with the measure total. You can use the ISINSCOPE function to control different levels to show different results.

 

Measure =
IF(ISINSCOPE(financials[Product]),"aaa",IF(ISINSCOPE('financials'[Country]),"bbb"))

 

vkaiyuemsft_0-1717999555227.png

 

In addition, these links may be helpful to you:

Dealing with Measure Totals - Microsoft Fabric Community

Measure Totals, The Final Word - Microsoft Fabric Community

 

If your Current Period does not refer to this, please clarify in a follow-up reply.

 

Best Regards,

Clara Gong

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

@v-kaiyue-msft  It seems like I cannot use the INSCOPE function in my measure, attaching the snap for your reference

Venkatesh__0-1718009700648.png

 

Hi @Venkatesh_ ,

 

This function is ISINSCOPE instead of INSCOPE. Also, please check whether the difference between your two numbers in the parent level is 0. If it is 0, you need to rewrite the calculation for it and then use the ISINSCOPE function to return its value.

 

Best Regards,

Clara Gong

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

Can you send me the revised measure please? I can't achieve yet.

Hi @Venkatesh_ ,

 

Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data. We can better understand the problem and help you.

 

Best Regards,

Clara Gong

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

Hi @v-kaiyue-msft  Attaching the PBIX sample file link for your reference. It says the problem with the matrix visual on Proj annual variance and variance on sell price. You wont see any sub total or total rows and if you see they are adding incorrect results. Thanks.

Sample PBI link: 
https://drive.google.com/drive/folders/1pXfcLfmEDZ0uaRRncSCeBIIBFSaVR_TI?usp=sharing

@v-kaiyue-msft  any update on this problem please?

fahadqadir3
Super User
Super User

@Venkatesh_ In your screenshot, last line (highlighted in red) is a SUBTOTAL VALUE or a site name VALUE ? I didn't see subtotal in your image attached, share a sample dataset or clear picture. Thank you

@fahadqadir3  First row is the sub total(row) of the product, attaching the full matrix visual, the grand total also shows zero for the meaures above,  If you see the first line, It should result approx "90.20" = (-185+90.48), same follows for variance of avg sell price as well.

Venkatesh__0-1717757951545.png

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.