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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
gkarlo
Frequent Visitor

Comparison LY with conditions

 I hope someone can help me, I need to count all projects released comparing from the last year, for example if I select April 2024, so the graphic or table must show me all months back since April 2023.

 

Table

DATEPROJECTS
01.2310
02.235
03.2310
04.2320
05.2310
06.2310
07.2320
08.2315
09.2315
10.235
11.2310
12.2310
01.2410
02.2412
03.2410
04.2410

 

I used SAMPLEDATE but only compares the specific month current year and the last year, but no all months among, and if I select the year, months as May....Dec are counted of the last year even if this year 2024, the months have not passed.

 

I look forward to your soon comments.

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

Hi @TomMartens ,thanks for the quick reply, I'll add further.

Hi @gkarlo ,

I have assumed some data as follows:

vzhouwenmsft_0-1714619081104.png

Please follow these steps:

1.Use the following DAX expression to create a column in 'Table'

Month = FORMAT([Date],"MM.YY")

2. Use the following DAX expression to create a table named 'Table 2'

Table 2 =
ADDCOLUMNS (
    CALENDAR ( DATE ( 2023, 1, 1 ), DATE ( 2024, 12, 31 ) ),
    "Month", FORMAT ( [Date], "MM.YY" ),
    "EndofMonth", EOMONTH ( [Date], 0 )
)

vzhouwenmsft_1-1714619236009.png

3.Use the following DAX expression to create a measure

Measure = 
VAR _a = SELECTEDVALUE('Table 2'[Month])
VAR _b = MAXX(FILTER('Table 2','Table 2'[Month] = _a),[EndofMonth])
VAR _c = DATE(YEAR(_b)-1,MONTH(_b),1)
VAR _d = COUNTX(FILTER('Table','Table'[Date] >= _c &&'Table'[Date] <= _b),[Projects])
RETURN IF(ISBLANK(_a),COUNT('Table'[Projects]),_d)

4.Final output

vzhouwenmsft_3-1714619505086.png

vzhouwenmsft_4-1714619517677.png

vzhouwenmsft_5-1714619535288.png

vzhouwenmsft_6-1714619555313.png

vzhouwenmsft_7-1714619581884.png

 

Best Regards,
Wenbin Zhou
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

View solution in original post

2 REPLIES 2
v-zhouwen-msft
Community Support
Community Support

Hi @TomMartens ,thanks for the quick reply, I'll add further.

Hi @gkarlo ,

I have assumed some data as follows:

vzhouwenmsft_0-1714619081104.png

Please follow these steps:

1.Use the following DAX expression to create a column in 'Table'

Month = FORMAT([Date],"MM.YY")

2. Use the following DAX expression to create a table named 'Table 2'

Table 2 =
ADDCOLUMNS (
    CALENDAR ( DATE ( 2023, 1, 1 ), DATE ( 2024, 12, 31 ) ),
    "Month", FORMAT ( [Date], "MM.YY" ),
    "EndofMonth", EOMONTH ( [Date], 0 )
)

vzhouwenmsft_1-1714619236009.png

3.Use the following DAX expression to create a measure

Measure = 
VAR _a = SELECTEDVALUE('Table 2'[Month])
VAR _b = MAXX(FILTER('Table 2','Table 2'[Month] = _a),[EndofMonth])
VAR _c = DATE(YEAR(_b)-1,MONTH(_b),1)
VAR _d = COUNTX(FILTER('Table','Table'[Date] >= _c &&'Table'[Date] <= _b),[Projects])
RETURN IF(ISBLANK(_a),COUNT('Table'[Projects]),_d)

4.Final output

vzhouwenmsft_3-1714619505086.png

vzhouwenmsft_4-1714619517677.png

vzhouwenmsft_5-1714619535288.png

vzhouwenmsft_6-1714619555313.png

vzhouwenmsft_7-1714619581884.png

 

Best Regards,
Wenbin Zhou
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

TomMartens
Super User
Super User

Hey @gkarlo ,

 

please take the time to create a pbix file that contains sample data but still reflects your semantic model (tables, relationships, calculated columns, and measures). Upload the pbix file to OneDrive, Google Drive, or dropbox and share the link. If you are using a spreadsheet to create the sample data, share the spreadsheet as well.

 

Do not forget to explain the expected result based on the sample data you provide.

 

Regards,

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.