Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

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
 
  • 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] )
        )

     

    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.

4 Replies

  • 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)
    )

    • Anonymous's avatar
      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

      Thanks for the response.Much helpful. 

       

  • v-kkf-msft's avatar
    v-kkf-msft
    Icon for Community Support rankCommunity 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] )
        )

     

    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's avatar
      Anonymous
      Not applicable

      Thanks a lot Winniz.Solution Worked just as expected 🙂