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

Irregular Quarter Comparison

Hi,

 

I have data for 4 quarters. The idea is to compare one particular column's value with the another.

 

Quarter             Value

2020q1             100

2020q2             200

2020q3             300

2020q4             400

 

I want to identify Current Quarter which should be the maximum of the ones i have selected and previous quarter which should be the minimum. So if i have 4 quarters 2020-Q1,Q2,Q3,Q4 and using slicer on quarter, if i select on q2 and q4

it should set CQ as value of q4 and for PQ it should set as of q2.

 

when q2 and q4 are selected

quarter   cq    pq

2020q2   200  blank

2020q4   400   200

 

 

 

 

1 ACCEPTED SOLUTION

Hi @Anonymous,

 

I'm not clear about the red mark:

vxulinmstf_0-1625813534803.png

When Q1 and Q2 selected, why aren't the places marked in red returning null values?

 

Try measure as:

CQ = 
var quar=
MAXX(
    ALLSELECTED('Table'[Quarter]),
    'Table'[Quarter])
return
MAXX(
    FILTER(
        ALL('Table'),
        'Table'[Quarter]=quar && 'Table'[Company]=MAX('Table'[Company]) && 'Table'[Deptt]=MAX('Table'[Deptt])
    ),
    'Table'[Value]
)
PQ = 
var _tab=
SUMMARIZE(
    ALLSELECTED('Table'),
    'Table'[Index],
    'Table'[Quarter],
    'Table'[Value],
    'Table'[Company],
    'Table'[Deptt]
)
return
MAXX(
    FILTER(
        _tab,
        [Index] < MAX('Table'[Index]) && 'Table'[Company]=MAX('Table'[Company]) && 'Table'[Deptt]=MAX('Table'[Deptt])
    ),
    [Value]
)

 Here is the output:

vxulinmstf_1-1625813677976.png

 

If you still have some question, please don't hesitate to let me known.‌‌

 

Best Regards,

Link

 

Is that the answer you're looking for? If this post helps, then please consider Accept it as the solution. Really appreciate!

 

 

View solution in original post

7 REPLIES 7
v-xulin-mstf
Community Support
Community Support

Hi @Anonymous

 

You need add a index column:

vxulinmstf_0-1625565718766.png

Try measure as:

PQ = 
var _tab=
SUMMARIZE(
    ALLSELECTED('Table'),
    'Table'[Index],
    'Table'[Quarter],
    'Table'[Value]
)
return
MAXX(
    FILTER(
        _tab,
        [Index] < MAX('Table'[Index])
    ),
    [Value]
)

Create column as:

CQ = 
CALCULATE(
    MAX('Table'[Value]),
    ALLSELECTED('Table'[Quarter])
)

Here is the output:

vxulinmstf_1-1625565791004.png

The pbix is attached.

If you still have some question, please don't hesitate to let me known.‌‌

 

Best Regards,

Link

 

Is that the answer you're looking for? If this post helps, then please consider Accept it as the solution. Really appreciate!

Anonymous
Not applicable

Hi,

 

Looks like your solution is correct although i am having trouble implementing it.

It is giving me same value for each PQ when implemented.

 

PQ_GO_1 =
var _tab=
SUMMARIZE(
ALLSELECTED('Data files'),
'Data files'[Index],
'Data files'[Quarter],
'Data files'[company],
'Data files'[dept],
'Data files'[salary]
)
return
MAXX(
FILTER(
_tab,
[Index] < MAX('Data files'[Index])
),
[salary]
)
 
 
I want to summarize it using company & deptt and get the total salary of each company & deptt wise. However, it is showing same value.
Any solution for this?

Hi @Anonymous,

 

Could you provide your sample data and expected output?

 

Best Regards,

Link

 

Is that the answer you're looking for? If this post helps, then please consider Accept it as the solution. Really appreciate!

Anonymous
Not applicable

Company     Deptt.   Quarter    Salary

ABC              Sales      2020Q1          10000

ABC              Sales      2020Q2           20000

ABC              Marketing  2020Q1       20000

ABC               Marketing  2020q3       50000

DEF              Accounts     2020q1        400000

DEF              Accounts     2020q2         400000

 

 

Final results should be when Q3 & q1 is selected

ABC      Sales              null      10000

ABC      Marketing     50000   20000

DEF       Accounts       400000   null

Hi @Anonymous,

 

I'm not clear about the red mark:

vxulinmstf_0-1625813534803.png

When Q1 and Q2 selected, why aren't the places marked in red returning null values?

 

Try measure as:

CQ = 
var quar=
MAXX(
    ALLSELECTED('Table'[Quarter]),
    'Table'[Quarter])
return
MAXX(
    FILTER(
        ALL('Table'),
        'Table'[Quarter]=quar && 'Table'[Company]=MAX('Table'[Company]) && 'Table'[Deptt]=MAX('Table'[Deptt])
    ),
    'Table'[Value]
)
PQ = 
var _tab=
SUMMARIZE(
    ALLSELECTED('Table'),
    'Table'[Index],
    'Table'[Quarter],
    'Table'[Value],
    'Table'[Company],
    'Table'[Deptt]
)
return
MAXX(
    FILTER(
        _tab,
        [Index] < MAX('Table'[Index]) && 'Table'[Company]=MAX('Table'[Company]) && 'Table'[Deptt]=MAX('Table'[Deptt])
    ),
    [Value]
)

 Here is the output:

vxulinmstf_1-1625813677976.png

 

If you still have some question, please don't hesitate to let me known.‌‌

 

Best Regards,

Link

 

Is that the answer you're looking for? If this post helps, then please consider Accept it as the solution. Really appreciate!

 

 

Anonymous
Not applicable

Perfect, it worked!

Greg_Deckler
Super User
Super User

@Anonymous Well, the previous quarter should be the MAXX of the values that are < the MAX (current quarter)


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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.