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
Varshi288
Resolver I
Resolver I

Filter Customers based on current year sales segment

Hello Community,

 I need help in the dax to filter customers based on sales range in the current year (2022) and to show sales of previous years as shown in the table. With the below dax Im getting error as attached in the snapshot. 

 

TP Segment = VAR _TP_Value =CALCULATE(MAX(Data[TP $]),FILTER(ALL(Data),Data[Customer HQ] =SELECTEDVALUE(Data[Customer HQ])),Period[Year]=YEAR(TODAY()))
            VAR _current_tp_ouput = IF(_TP_Value>=50000 && _Tp_value<=100000,_Tp_value,BLANK())
            RETURN
            IF(_current_tp_ouput<>BLANK(),MAX(Data[TP $]),BLANK())

 

 Slicer selected 100k t0 150k.

Customer202020212022
AA150k100k150K
AA2100K150K50K
AA3200K100k250k
AA4180k 120k
AA5100k120k60k
    
Result   
Customer202020212022
AA150k100k150K
AA4180k 120k

 

 

Varshi288_0-1668170089257.png

 

 

 

 

 

 

4 REPLIES 4
v-shex-msft
Community Support
Community Support

Hi @Varshi288 ,

Did the above suggestions help with your scenario? if that is the case, you can consider Kudo or Accept the helpful suggestions to help others who faced similar requirements.

If these also don't help, please share more detailed information to help us clarify your scenario to test.

How to Get Your Question Answered Quickly 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Hi  @Xiaoxin Sheng

 

That didnt work in my data model. In the measure Vallue 2022 year is hard coded. it should dynamically select the year i.e  in Jan 2023 it should take 2023.Here the sample  pbix.

 

https://drive.google.com/file/d/1VNQtS65nT9Zj3nvpOzhRlijYM4OEzE1x/view?usp=share_link

Hi @Varshi288,

You can try to use the following measure formula if it suitable for your requirement: (it will filter records based  on the what if parameter table selections)

TP Segment = 
VAR _TP_Value =
    CALCULATE (
        MAX ( Data[TP $] ),
        ALL ( Data ),
        VALUES ( Period[Year] ),
        VALUES ( Customer[Customer] )
    )
VAR selection =
    ALLSELECTED ( Parameter[Parameter] )
VAR _start =
    MINX ( selection, [Parameter] )
VAR _end =
    MAXX ( selection, [Parameter] )
VAR _current_tp_ouput =
    IF ( _TP_Value >= _start && _Tp_value <= _end, _Tp_value, BLANK () )
RETURN
    IF ( _current_tp_ouput <> BLANK (), MAX ( Data[TP $] ) )

1.png

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.
lbendlin
Super User
Super User

First step is to unpivot your data.

lbendlin_0-1668259745308.png

 

Then you need to define what "current" year means for you.   This will be impacted by the filter context unless you tell it otherwise.

Let's assume you mean 2022 as you mention.  Create a calculated column of the 2022 value for each of your customers. (You cannot use a measure as measures cannot feed slicers)

Value 2022 = CALCULATE(sum('Table'[Value]),ALLEXCEPT('Table','Table'[Customer]),'Table'[Year]="2022")

Use this column for your slicer. 

lbendlin_1-1668260107220.png

 

Which gives you the desired result (albeit a different one than you indicated).

lbendlin_2-1668260234319.png

see attached

 

 

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.