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
Manisha_91
Helper I
Helper I

DAX to identify time period selection for ALL Markets where they have common date (Month-Year) data

Hi Team,

 

I am new to Power BI and trying to create a DAX to identify time period selection for ALL Markets where they have common date (Month-Year) data available.

 

For example: The Sales data avaliable for all the markets are as below:

MarketLatest Data Available Date Range
USAOct 2021 - May 2022
SpainOct 2021 - July 2022
UKOct 2021 - June 2022
ItalyOct 2021 - May 2022
GermanyOct 2021 - May 2022
FranceOct 2021 - July 2022
RussiaOct 2021 - May 2022

 

Requirement is to showcase the market sales for common Max date data available.
For example The report should showcase Sales data from Oct 2021 till May 2022 for All Markets.

 

Can anyone help me with the dax formula for this?

1 ACCEPTED SOLUTION

Hi @Manisha_91 
Sorry for the late reply. It turned out I have a problem with my dropbox. Anyway, here is the sample file with the updated solution based on date table https://we.tl/t-ptCNoiaUEL

Filter Measure = 
VAR CurrentDate = 
    CALCULATE ( SELECTEDVALUE ( DimDate[Date] ), CROSSFILTER ( DimDate[Date], Sales[Date], BOTH ) )
VAR T1 =
    CALCULATETABLE ( SUMMARIZE ( Sales, Sales[Market], Sales[Date] ), ALL ( DimDate ), ALL ( Sales[Market] ) )
VAR T2 = 
    ADDCOLUMNS ( 
        T1, 
        "@MaxDate", CALCULATE ( MAX ( Sales[Date] ), ALLEXCEPT ( Sales, Sales[Market] ) ),
        "@MinDate", CALCULATE ( MIN ( Sales[Date] ), ALLEXCEPT ( Sales, Sales[Market] ) ) 
    )
VAR T3 =
    FILTER ( T2, [Date] = [@MaxDate] )
VAR T4 =
    FILTER ( T2, [Date] = [@MinDate] )
VAR LastCommonDate =
    MINX ( T3, [Date] )
VAR FirstCommonDate =
    MAXX ( T4, [Date] )
VAR Result =
    IF ( CurrentDate >= FirstCommonDate && CurrentDate <= LastCommonDate, 1 )
RETURN
    Result

 

View solution in original post

12 REPLIES 12
tamerj1
Super User
Super User

Hi @Manisha_91 
Sorry for the late reply, I was about to leave the office when I received your feedback. I hope I correctly understand. You want to filter your report for the dates that are less than or equal to maximum common date of all markets. Here is is a sample file with the solution https://www.dropbox.com/t/tqGbPqbyVVSPFLXH

Most probably your data model is a bit different. However, if it does not work with your actual data model then minor amendments to the code shall be enough to get it work.

You need to create a filter measure, place it in the filter pane, select "Is not blank" and apply the filter.

Please let me know if you have any question.

1.png4.png2.png3.png

Filter Measure = 
VAR CurrentDate = 
    SELECTEDVALUE ( Sales[Date] )
VAR T1 =
    CALCULATETABLE ( SUMMARIZE ( Sales, Sales[Market], Sales[Date] ), ALL ( Sales[Market], Sales[Date] ) )
VAR T2 = 
    ADDCOLUMNS ( T1, "@MaxDate", CALCULATE ( MAX ( Sales[Date] ), ALL ( Sales[Date] ) ) )
VAR T3 =
    FILTER ( T2, [Date] = [@MaxDate] )
VAR LastCommonDate =
    MINX ( T3, [Date] )
VAR Result =
    IF ( CurrentDate <= LastCommonDate, 1 )
RETURN
    Result

Hi @tamerj1 ,

I tried this solution with my data. It is returning 1 for all the months even the one that are not common amognst the Markets. Please refer the screenshot attached.

Manisha_91_0-1659361259966.png

Also, I am not able to see the attachment you had in dropbox. It is giving error.
Could you please try uploading it again?

@Manisha_91 

I'll find the and share it with you. Mean while would you please elaborate on you data model

@tamerj1 

I have one fact table (Fact Retail Sales) and 2 dimemsion Tables dimTime and dimProduct

Fact table structure:

Manisha_91_0-1659364859532.png

 

dimTime Structure:

Manisha_91_1-1659364956053.png

Join is one to Many and primary key is 'Date' column

Requirement is - 
We are working on 3 months, 6 months latest period selection which are common between all the markets which in this screnario should be 
3 Month -> Mar 2022 to May 2022
6 Month -> Dec 2021 to May 2022

If I am selecting latest three month slicer it shows data as below screenshot:

Manisha_91_2-1659365336320.png


As we see Spain and Australia have June Month data as well in fact table but other markets do not have it so we want to showcase data till May 2022 for All Markets.

Hi @Manisha_91 
Sorry for the late reply. It turned out I have a problem with my dropbox. Anyway, here is the sample file with the updated solution based on date table https://we.tl/t-ptCNoiaUEL

Filter Measure = 
VAR CurrentDate = 
    CALCULATE ( SELECTEDVALUE ( DimDate[Date] ), CROSSFILTER ( DimDate[Date], Sales[Date], BOTH ) )
VAR T1 =
    CALCULATETABLE ( SUMMARIZE ( Sales, Sales[Market], Sales[Date] ), ALL ( DimDate ), ALL ( Sales[Market] ) )
VAR T2 = 
    ADDCOLUMNS ( 
        T1, 
        "@MaxDate", CALCULATE ( MAX ( Sales[Date] ), ALLEXCEPT ( Sales, Sales[Market] ) ),
        "@MinDate", CALCULATE ( MIN ( Sales[Date] ), ALLEXCEPT ( Sales, Sales[Market] ) ) 
    )
VAR T3 =
    FILTER ( T2, [Date] = [@MaxDate] )
VAR T4 =
    FILTER ( T2, [Date] = [@MinDate] )
VAR LastCommonDate =
    MINX ( T3, [Date] )
VAR FirstCommonDate =
    MAXX ( T4, [Date] )
VAR Result =
    IF ( CurrentDate >= FirstCommonDate && CurrentDate <= LastCommonDate, 1 )
RETURN
    Result

 

Thanks @tamerj1 This really helps. 🙂

tamerj1
Super User
Super User

Hi @Manisha_91 
Seems something missing here. Where are the values of the latest data available?

..

@Manisha_91 
Tahnks for clarifying, please advise what would be the expected results for this sample data?

@tamerj1 , I am expecting that if all Markets have May 2022 data then the report should only reflect data till May 2022.

Basically a Max cutoff for All Markets should be same.
As in Sample data we see Spain, UK and France have data more than May 2022 but if we can build a measure we can provide a cutoff till May 2022. I hope I am making sense here.

@Manisha_91 
Thank you. Please consider that I'm not looking at your data neither do I have any idea what is it. So please bare with me. So you row data is preseneted exactly as you stated in the sample above? And yes we can limit the any calculation up the latest common date (May 2022) but what calculation? What exactly are you trying to limit? 

@tamerj1 

 

My Report has different Sales related insights.

We want to limit the sales data to reflect insights till a date that is common in All the Markets. 

Please refer the table below as I have added Sales amount column as well per month:

 

MarketDate Sales 
USAOct-21 $    25,000
USANov-21 $    23,156
USADec-21 $    20,000
USAJan-22 $    14,789
USAFeb-22 $    45,987
USAMar-22 $    23,452
USAApr-22 $    32,141
USAMay-22 $    11,212
SpainOct-21 $    45,987
SpainNov-21 $    23,452
SpainDec-21 $    32,141
SpainJan-22 $    65,467
SpainFeb-22 $    32,211
SpainMar-22 $    54,543
SpainApr-22 $  345,265
SpainMay-22 $    65,311
SpainJun-22 $    90,123
SpainJul-22 $    54,376
UKOct-21 $    32,141
UKNov-21 $    65,467
UKDec-21 $    32,211
UKJan-22 $    14,789
UKFeb-22 $    45,987
UKMar-22 $    23,452
UKApr-22 $    32,141
UKMay-22 $    50,000
UKJun-22 $    65,345
ItalyOct-21 $    45,987
ItalyNov-21 $    23,452
ItalyDec-21 $    32,141
ItalyJan-22 $    65,467
ItalyFeb-22 $    32,211
ItalyMar-22 $    54,543
ItalyApr-22 $    14,789
ItalyMay-22 $    45,987
GermanyOct-21 $    21,212
GermanyNov-21 $    35,213
GermanyDec-21 $    85,453
GermanyJan-22 $    90,000
GermanyFeb-22 $  152,012
GermanyMar-22 $    57,481
GermanyApr-22 $    32,123
GermanyMay-22 $    22,514
FranceOct-21 $    23,156
FranceNov-21 $    20,000
FranceDec-21 $    14,789
FranceJan-22 $    45,987
FranceFeb-22 $    23,452
FranceMar-22 $    65,467
FranceApr-22 $    32,211
FranceMay-22 $    14,789
FranceJun-22 $    45,987
RussiaOct-21 $    23,452
RussiaNov-21 $    23,452
RussiaDec-21 $    32,141
RussiaJan-22 $    65,467
RussiaFeb-22 $    32,211
RussiaMar-22 $    42,000
RussiaApr-22 $    32,500
RussiaMay-22 $    38,562

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.