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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

Measure calculation when no items existing in the source table

Hi all,

 

I'm trying to build a measure that compute a value depending on a field from the table.

 

Here is my model

2022-02-28 15_16_33-Power Pivot pour Excel - TestUnPourCent.xlsx.png

Here are the datas.

 

2022-02-28 15_16_03-TestUnPourCent.xlsx - Excel.png

In Dax Studio I have the following measure definition.

DEFINE

MEASURE TBSource[sum1]=
	var result = CALCULATE(sum(TBSource[Quantity]))
	RETURN IF (ISBLANK(result),0, IF(result< 0,0,result))

var tb = SUMMARIZECOLUMNS(
	TBName[Name],
	TBSource[Code],
	"sum1", [sum1]
	)


EVALUATE tb

 

the result is the following

 

2022-02-28 15_19_40-DaxStudio - 2.17.3.png

 

What I try to do is, when C3=0, then I want to change the quantity to 5.

The problem is that no datas exists for this code and the Name AA. How can I do that ? And I do not want to have this rule applied to C2, wich has also no data for the name BB.

 

Thanks for your help,

 

 

1 ACCEPTED SOLUTION
v-easonf-msft
Community Support
Community Support

Hi, @Anonymous 

You can change you formula as below:

DEFINE
    MEASURE TBSource[sum1] =
        VAR result =
            CALCULATE ( SUM ( TBSource[Quantity] ) )
        RETURN
            IF ( ISBLANK ( result ), 0, IF ( result < 0, 0, result ) )
    VAR tb =
        ADDCOLUMNS (
            SUMMARIZECOLUMNS ( TBName[Name], TBSource[Code] ),
            "sum1",
                IF ( TBSource[Code] = "C3" && TBSource[sum1] = 0, 5, TBSource[sum1] )
        )

EVALUATE
tb

Best Regards,
Community Support Team _ Eason

View solution in original post

3 REPLIES 3
v-easonf-msft
Community Support
Community Support

Hi, @Anonymous 

You can change you formula as below:

DEFINE
    MEASURE TBSource[sum1] =
        VAR result =
            CALCULATE ( SUM ( TBSource[Quantity] ) )
        RETURN
            IF ( ISBLANK ( result ), 0, IF ( result < 0, 0, result ) )
    VAR tb =
        ADDCOLUMNS (
            SUMMARIZECOLUMNS ( TBName[Name], TBSource[Code] ),
            "sum1",
                IF ( TBSource[Code] = "C3" && TBSource[sum1] = 0, 5, TBSource[sum1] )
        )

EVALUATE
tb

Best Regards,
Community Support Team _ Eason

AlexisOlson
Super User
Super User

It sounds like your data is incomplete. I'd recommend appending a new row to your TBSource table before loading it into your model rather than trying to add data via measures.

tamerj1
Super User
Super User

@Anonymous 

Not sure about data lineage but you may try

sum1 =
VAR tb1 =
SUMMARIZE ( TBName[Name], TBSource[Code], "sum1", SUM ( TBSource[Quantity] ) )
VAR tb2 =
ADDCOLUMNS (
tb1,
"@sum1",
SWITCH (
TRUE,
[Code] = "C3"
&& [sum1] = 0, 5,
ISBLANK ( [sum1] ), 0,
[sum1] < 0, 0,
[sum1]
)
)
RETURN
SUMX ( tb2, CALCULATE ( SUM ( [@sum1] ) ) )

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.