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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

DAX Calculate IN

Hello, I'm pretty new to writing DAX.

 

I've created Measure that CALCULATE SUM of VALUE IN specified PERIOD

 

Here is a formula:

Plan III'18 = CALCULATE(
   SUM(Table[Plan]);
   Table[Quarter] IN { "III'2018" }
)

Its calculate sum of values from PLAN = III'2018

This formula works fine, when user selected in slicer Quarter = IV'2018 he could find values of PLAN for Selected QUARTER and see values for Prev Quarter

 

But I want to change behaviour of this Measure to calculate always sum of values from Previous Quarter

 

For example, if user selected in slicer III'2018 (instead of IV'2018) it will show him values for II'2018 (-1 QUARTER)

 

What I have in "Table"

Columns names

  • Subject (char)
  • Quarter (char)
  • Plan (int)
  • Quarter Prev (char) 

 

Thanks in advance 

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

Hi @Anonymous,

 

One sample for your reference.

 

1. Create a calculated table as below.

 

Table = UNION(VALUES(Table1[Quarter]),VALUES(Table1[Quarter Prev]))

2. Creat a measure to get the result as we need.

 

Measure = 
VAR _sele =
    SELECTEDVALUE ( 'Table'[Quarter] )
VAR _pre =
    SWITCH (
        _sele,
        "IV'2018", "III'2018",
        "III'2018", "II'2018",
        "II'2018", "I'2018",
        "I'2018", "IV'2017"
    )
RETURN
    IF (
        ISBLANK ( _sele ),
        BLANK (),
        CALCULATE ( SUM ( Table1[Plan] ), FILTER ( Table1, Table1[Quarter] = _pre ) )
    )

Capture.PNG

Also please find the pbix as attached.

 

Regards,

Frank

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.

View solution in original post

1 REPLY 1
v-frfei-msft
Community Support
Community Support

Hi @Anonymous,

 

One sample for your reference.

 

1. Create a calculated table as below.

 

Table = UNION(VALUES(Table1[Quarter]),VALUES(Table1[Quarter Prev]))

2. Creat a measure to get the result as we need.

 

Measure = 
VAR _sele =
    SELECTEDVALUE ( 'Table'[Quarter] )
VAR _pre =
    SWITCH (
        _sele,
        "IV'2018", "III'2018",
        "III'2018", "II'2018",
        "II'2018", "I'2018",
        "I'2018", "IV'2017"
    )
RETURN
    IF (
        ISBLANK ( _sele ),
        BLANK (),
        CALCULATE ( SUM ( Table1[Plan] ), FILTER ( Table1, Table1[Quarter] = _pre ) )
    )

Capture.PNG

Also please find the pbix as attached.

 

Regards,

Frank

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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