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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Anonymous
Not applicable

Month sum of measure calculated on Date level

Hi,

 

I'm trying to create measures that will handle filtering on a date and time level for the start end end date.
For this I'm using a normal date slicer, and then filtering start and end time based on the min/max dates in the selected range, using two seperate tables as input variables for the start and end time.

 

Currently I have the measure listed below, which works as intended, but I need to figure out how to get the correct total, when not filtering on a date level.

 

I get that the measure returns blank when not filtering on a Date level due to the 'HASONEVALUE', but I'm using the 'HASONEVALUE' to return a single scalar value into the following if statements.

How do I feed the if statements with a single value, but get the correct total value shown at a year or month level?

Sales Revenue = 
VAR MinDato = CALCULATE(MIN(Periode[Dato]);ALLSELECTED(Periode[Dato]))
VAR MaxDato = CALCULATE(MAX(Periode[Dato]);ALLSELECTED(Periode[Dato]))
VAR MaxTime = CALCULATE(MAX('Time min filter'[Time]))
VAR MAXTimeMaxDato = CALCULATE(MAX('Time max filter'[Time]))
RETURN
 IF( HASONEVALUE(Periode[Dato]);
			IF(VALUES(Periode[Dato]) = MinDato;
				CALCULATE(Sales[Sales Revenue];
					FILTER('Periode Tidspunkt';'Periode Tidspunkt'[Time] >= MaxTime));
			IF(VALUES(Periode[Dato]) = MaxDato;
				CALCULATE(Sales[Sales Revenue];
					FILTER('Periode Tidspunkt';'Periode Tidspunkt'[Time] <= MAXTidspunktMaxDato));
					Sales[Sales Revenue]));
					BLANK())

Note:
Measure is mainly in danish so:
Dato = Date
Periode = Date table

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Cracked it by more googling and turning to switch for help and referencing another table

 

Final measure:

Salg Oms Switch Filter = 
VAR MinDato = CALCULATE(MIN(Periode[Dato]);ALLSELECTED(Periode[Dato]))
VAR MaxDato = CALCULATE(MAX(Periode[Dato]);ALLSELECTED(Periode[Dato]))
VAR MaxTidspunkt = CALCULATE(MAX('Tidspunkt min filter'[Time]))
VAR MAXTidspunktMaxDato = CALCULATE(MAX('Tidspunkt max filter'[Time]))
RETURN
DIVIDE(
SUMX(Salg;
	SWITCH( TRUE();
			Salg[Bogføringsdato] = MinDato;CALCULATE(Salg[Salg Omsætning];
						FILTER('Periode Tidspunkt';'Periode Tidspunkt'[Time] >= MaxTidspunkt));
			Salg[Bogføringsdato] = MaxDato;
					CALCULATE(Salg[Salg Omsætning];
						FILTER('Periode Tidspunkt';'Periode Tidspunkt'[Time] <= MAXTidspunktMaxDato));
			Salg[Salg Omsætning]))
			;1000)

View solution in original post

1 REPLY 1
Anonymous
Not applicable

Cracked it by more googling and turning to switch for help and referencing another table

 

Final measure:

Salg Oms Switch Filter = 
VAR MinDato = CALCULATE(MIN(Periode[Dato]);ALLSELECTED(Periode[Dato]))
VAR MaxDato = CALCULATE(MAX(Periode[Dato]);ALLSELECTED(Periode[Dato]))
VAR MaxTidspunkt = CALCULATE(MAX('Tidspunkt min filter'[Time]))
VAR MAXTidspunktMaxDato = CALCULATE(MAX('Tidspunkt max filter'[Time]))
RETURN
DIVIDE(
SUMX(Salg;
	SWITCH( TRUE();
			Salg[Bogføringsdato] = MinDato;CALCULATE(Salg[Salg Omsætning];
						FILTER('Periode Tidspunkt';'Periode Tidspunkt'[Time] >= MaxTidspunkt));
			Salg[Bogføringsdato] = MaxDato;
					CALCULATE(Salg[Salg Omsætning];
						FILTER('Periode Tidspunkt';'Periode Tidspunkt'[Time] <= MAXTidspunktMaxDato));
			Salg[Salg Omsætning]))
			;1000)

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors