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
Anonymous
Not applicable

how to make measure return 0 but not for applicable months

I have some measure, say [Total Sales].  This measures appears on a table visual, along with field 'Dimension Month'[Month Name].  This dimension table will have more months than those in 'Fact Sales' table (e.g., future months).  For those in 'Fact Sales', 'Dimension Month'[Has Sales] = "Yes"; for those that are not in, 'Dimension Month'[Has Sales] = "No".  Even for those that are in 'Fact Sales', there might not be any sales (e.g., [Total Sales] will be blank).

 

I want [Total Sales] to return zero for months with no sales, but only where 'Dimension Month'[Has Sales] = "Yes"; otherwise, I want [Total Sales] to be blank.

 

For example, instead of 

Month Name          Has Sales       Total Sales

A                              Yes                25

B                               Yes                blank

C                               No                 blank

 

I want:

Month Name          Has Sales       Total Sales

A                              Yes                25

B                               Yes                0

C                               No                 blank

 

How can I achieve this?

1 ACCEPTED SOLUTION
PhilipTreacy
Super User
Super User

Hi @Anonymous 

Calculate your [Total Sales] and store that in a VAR, test to see if it is BLANK and check 'Dimension Month'[Has Sales] for Yes/No.  Then return the appropriate value. Something like this

Total Sales =

VAR TS = SUM('Table'[Sales])

RETURN

	SWITCH(

	TRUE(),

	ISBLANK(TS) && 'Dimension Month'[Has Sales] = "Yes", 0,

	TS

	)

regards

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


View solution in original post

1 REPLY 1
PhilipTreacy
Super User
Super User

Hi @Anonymous 

Calculate your [Total Sales] and store that in a VAR, test to see if it is BLANK and check 'Dimension Month'[Has Sales] for Yes/No.  Then return the appropriate value. Something like this

Total Sales =

VAR TS = SUM('Table'[Sales])

RETURN

	SWITCH(

	TRUE(),

	ISBLANK(TS) && 'Dimension Month'[Has Sales] = "Yes", 0,

	TS

	)

regards

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


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.