cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Sniv
Frequent Visitor

Exclude a column from a filter

Hello,

 

I would like to exclude a column from the DATEINPERIOD filter or make sure that this filter only concerns certain columns in a calculation using the CALCULATE function.

 

Durée moyenne par session cumulée au mois =
CALCULATE(SUM('Google analytics'[Number of sessions])/SUM('Google analytics'[Cumulative number of session each week])*SUM('Google analytics'[Average time per session]),
ALL('Google analytics'),
DATESINPERIOD(
'Google analytics'[Date],
FIRSTDATE('Google analytics'[Date]),
-1,
MONTH)

 

I want to exclude [Cumulative number of session each week] from the DATESINPERIOD FILTER or make the filter affect only [Number of sessions] and [Average time per session].

I put an example below.

 

Thank you in advance for your answers.

1 ACCEPTED SOLUTION
SpartaBI
Community Champion
Community Champion

@Sniv In addition to your question, I saw how you used the data column inside the DATESINPERIOD function. This is not how you should do that. Either you have a dim dates you created or you use the autodate time table. 
For simplicity, let's say you use the autodate time, than your measure is:

 

DIVIDE(
	CALCULATE (
	    SUM ( 'Google analytics'[Number of sessions] )
	        * SUM ( 'Google analytics'[Average time per session] ),
	    DATESINPERIOD (
	        'Google analytics'[Date].[Date],
	        FIRSTDATE ( 'Google analytics'[Date] ),
	        -1,
	        MONTH
	    )
	),
	 SUM ( 'Google analytics'[Cumulative number of session each week] )
)

 

Pay attention to the version I used:
'Google analytics'[Date].[Date]

Also, you don't need the ALL argument as you play with filters on the date table anyway.


2022-05-19 17_30_22-Re_ Need help on DAX function with measure vs colu... - Microsoft Power BI Commu.png

Showcase Report – Contoso By SpartaBI


SpartaBI_3-1652115470761.png   SpartaBI_1-1652115142093.png   SpartaBI_2-1652115154505.png

Full-Logo11.png

View solution in original post

3 REPLIES 3
SpartaBI
Community Champion
Community Champion

@Sniv In addition to your question, I saw how you used the data column inside the DATESINPERIOD function. This is not how you should do that. Either you have a dim dates you created or you use the autodate time table. 
For simplicity, let's say you use the autodate time, than your measure is:

 

DIVIDE(
	CALCULATE (
	    SUM ( 'Google analytics'[Number of sessions] )
	        * SUM ( 'Google analytics'[Average time per session] ),
	    DATESINPERIOD (
	        'Google analytics'[Date].[Date],
	        FIRSTDATE ( 'Google analytics'[Date] ),
	        -1,
	        MONTH
	    )
	),
	 SUM ( 'Google analytics'[Cumulative number of session each week] )
)

 

Pay attention to the version I used:
'Google analytics'[Date].[Date]

Also, you don't need the ALL argument as you play with filters on the date table anyway.


2022-05-19 17_30_22-Re_ Need help on DAX function with measure vs colu... - Microsoft Power BI Commu.png

Showcase Report – Contoso By SpartaBI


SpartaBI_3-1652115470761.png   SpartaBI_1-1652115142093.png   SpartaBI_2-1652115154505.png

Full-Logo11.png

Sniv
Frequent Visitor

@SpartaBI Thanks for your answer, I understand now how to use it ! 7

It works perfectly !

SpartaBI
Community Champion
Community Champion

@Sniv my pleasure 🙂
Hey, check out my showcase report - got some high level stuff there 🙂
https://community.powerbi.com/t5/Data-Stories-Gallery/SpartaBI-Feat-Contoso-100K/td-p/2449543
Give it a thumbs up over there if you liked it 🙂

Helpful resources

Announcements
Carousel_PBI_Wave1

2023 Release Wave 1 Plans

Power BI release plans for 2023 release wave 1 describes all new features releasing from April 2023 through September 2023.

Power BI Summit Carousel 2

Global Power BI Training

Make sure you register today for the Power BI Summit 2023. Don't miss all of the great sessions and speakers!

BizApps LATAM 2023

Business Application LATAM Summit 2023

Join the biggest FREE Business Applications Event in LATAM this February.

Power Platform Bootcamp

Global Power Platform Bootcamp

In this bootcamp we will deep-dive into Microsoft’s Power Platform stack with hands-on sessions and labs, delivered to you by experts and community leaders.

Top Solution Authors
Top Kudoed Authors