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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Dax Replace selectedvalue in measure

Hi All,

In the below given data for paticular material if Calender month and Posting Calender month are equal then Result A or else Result B.

 

Material NumberBatch NumberCALENDAR_MONTHCALENDAR_YEARPosting_CALENDAR_MONTHPosting_CALENDAR_YEAREndstock
FA03 1202212022 
FA03 1202212022 
FA03DS12022120220
FA03DS12202112022500
FA03BS1202212022730
FA03BS12202112022730
FA07DS92021120222300

Below is the dax measure am using and it is direct query.Only Posting_CALENDAR_MONTH is being used in slicer.

Measure=

var selCD = SELECTEDVALUE(DP_ZIC_C06[Posting_CALENDAR_MONTH])
RETURN
IF(Selectedvalue(DP_ZIC_C06[CALENDAR_MONTH])=SelCD,CALCULATE (
SUM(
DP_ZIC_C06[END_STOCK]
)
),CALCULATE (
SUM (
DP_ZIC_C06[END_STOCK]
)
),
SELECTEDVALUE ( DP_ZIC_C06[Posting_CALENDAR_MONTH] ) <> DP_ZIC_C06[CALENDAR_MONTH]
))
expected o/p
Material NumberBatch NumberEndstock
FA03DS0
FA03BS730
FA07DS2300
 
1 ACCEPTED SOLUTION
v-kkf-msft
Community Support
Community Support

Hi @Anonymous ,

 

Please try the following formula:

 

Measure = 
VAR selCD =
    SELECTEDVALUE ( DP_ZIC_C06[Posting_CALENDAR_MONTH] )
VAR tab =
    FILTER ( DP_ZIC_C06, DP_ZIC_C06[CALENDAR_MONTH] = SelCD )
RETURN
    IF (
        COUNTROWS ( tab ) > 0,
        CALCULATE ( SUM ( DP_ZIC_C06[END_STOCK] ), tab ),
        SUM ( DP_ZIC_C06[END_STOCK] )
    )

vkkfmsft_0-1646985688265.png

 

If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
Best Regards,
Winniz
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
v-kkf-msft
Community Support
Community Support

Hi @Anonymous ,

 

Please try the following formula:

 

Measure = 
VAR selCD =
    SELECTEDVALUE ( DP_ZIC_C06[Posting_CALENDAR_MONTH] )
VAR tab =
    FILTER ( DP_ZIC_C06, DP_ZIC_C06[CALENDAR_MONTH] = SelCD )
RETURN
    IF (
        COUNTROWS ( tab ) > 0,
        CALCULATE ( SUM ( DP_ZIC_C06[END_STOCK] ), tab ),
        SUM ( DP_ZIC_C06[END_STOCK] )
    )

vkkfmsft_0-1646985688265.png

 

If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
Best Regards,
Winniz
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

Thanks a lot Winniz.Solution Worked just as expected 🙂

amitchandak
Super User
Super User

@Anonymous , Try

 


Measure=
var selCD = SELECTEDVALUE(DP_ZIC_C06[Posting_CALENDAR_MONTH])
RETURN
IF(max(DP_ZIC_C06[CALENDAR_MONTH])=SelCD,CALCULATE (
SUM(
DP_ZIC_C06[END_STOCK]
)
),CALCULATE (
SUM (
DP_ZIC_C06[END_STOCK]
), filter( DP_ZIC_C0, DP_ZIC_C06[CALENDAR_MONTH] <> _selCD)
)
)

 

or


Measure=
var selCD = SELECTEDVALUE(DP_ZIC_C06[Posting_CALENDAR_MONTH])
RETURN
calculate( SUM(
DP_ZIC_C06[END_STOCK] ), filter( DP_ZIC_C0, DP_ZIC_C06[CALENDAR_MONTH] = _selCD) ) + CALCULATE (
SUM (
DP_ZIC_C06[END_STOCK]
), , filter( DP_ZIC_C0, DP_ZIC_C06[CALENDAR_MONTH] <> _selCD)
)

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

@amitchandak  Solution is not giving me expected result.Please see the edited post.

In Measure for Material FA03,Batchnumber DS value should be 0 as Calender month and CCFOT calender date are same

harinikambam_0-1646728058736.png

Thanks for the response.Much helpful. 

 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.