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
paweldm
Helper II
Helper II

Waterfall chart for opened, closed, last period breakdown

Hi there,

 

I am trying to apply the idea of the waterfall chart developed by  @SqlJason to present breakdown of active pharmacies per selected year . It is available here: http://sqljason.com/2015/08/using-dax-to-make-your-power-bi-dataviz.html

 

I need the following measures:

 

# of opened pharmacies (selected year)

# of closed pharmacies (selected year)

# of active pharmacies (year before the selected one)

 

I only have the measure to calculate # of active pharmacies and I belive that the function SAMEPERIODLASTYEAR could be helpful to get the 3 rd measure. 

 

 

Pharmacy Active = CALCULATE(
	COUNT('pharmacy'[pharmaid]);
		FILTER(
				'pharmacy';
				'pharmacy'[opendate] <= LASTDATE('Date'[Date]) &&
				('pharmacy'[closeDate] >= FIRSTDATE('Date'[Date]) || ISBLANK('pharmacy'[closeDate]))
			)
)

 

Can anyone help me to deal with my case?

 

Pawel

 

 

 

 

 

 

 

 

 

 

1 ACCEPTED SOLUTION

OK, here should be the final answers (I am putting all of the DAX in so this post can be marked as the solution and have all of the answers):

 

Pharmacies Opened in a given year

Pharmacy Opened = 
CALCULATE (
    COUNT ( 'pharmacy'[pharmaid] ) ,
    FILTER('pharmacy',
                 'pharmacy'[openDate] >= FIRSTDATE ( 'Date'[Date] ) && 
                 'pharmacy'[openDate] <= LASTDATE ('Date'[Date])
	      )
)

Pharmacy Closed in a given year

 

Pharmacy Closed = 
CALCULATE (
    COUNT ( 'pharmacy'[pharmaid] ) ,
    FILTER('pharmacy',
                 'pharmacy'[opendate] <= LASTDATE ( 'Date'[Date] ) &&
                 'pharmacy'[closeDate] >= FIRSTDATE ( 'Date'[Date] ) && 
                 'pharmacy'[closeDate] <= LASTDATE ('Date'[Date])
                 )
    ) 

 

To calculate the number of currently active pharmacies in a given year (based on the slicer), we are going to create two measures that will denote whether or not the pharmacy was opened prior or during to the selected year(s) (by giving a value of 1) and/or closed prior to or during the selected years (giving a value of -1)

IsOpen =
IF (
    CALCULATE ( MINX ( pharmacy, pharmacy[openDate] ) ) <= LASTDATE ( 'Date'[Date] ),
    1,
    0
)

 

 

IsClosed =
VAR minDate =
    CALCULATE ( MINX ( pharmacy, pharmacy[closedate] ) )
RETURN
    IF (
        AND ( minDate <= LASTDATE ( 'Date'[Date] ), NOT ( ISBLANK ( minDate ) ) ),
        -1,
        0
    )

Finally, the number of current active pharmacies is simply the sum of IsOpen and IsClosed

 

 

Pharmacy Active =
CALCULATE ( SUMX ( pharmacy, [IsOpen] ) + SUMX ( pharmacy, [IsClosed] ) )

And the number of active pharmacies in the year prior to the minimum selected year

 

 

Pharmacy Active LY = 
VAR minSelYear =
    YEAR ( CALCULATE ( MIN ( 'Date'[Date] ), ALLSELECTED ( 'Date'[Year] ) ) )
VAR PAMinSel =
    CALCULATE ( [Pharmacy Active], 'Date'[Year] = minSelYear - 1 )
RETURN
    IF ( ISBLANK ( PAMinSel ), 0, PAMinSel )

 

Let me know how the rest of the report goes.

David

View solution in original post

13 REPLIES 13

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.