Category Archives: Tabular

How to Automate Processing of Azure Analysis Services Models

I’ve been working on a proof of concept for a customer that involved using Azure Analysis Services as a cache for some data in an Azure Data Warehouse instance. One of the things I’ve been working on is scheduling the automatic processing of the Azure AS database. I did find the following documentation on the process, but the screenshots of the Azure portal are out of date and I did find some errors in the instructions. I also found this very extensive project for partition management in Azure AS, but this was a little overkill for my purposes and I was just interested in the very basics.

Read my recap for MS Data Summit here

These previously mentioned resources led me to write this blog post. In this post I’m going to leverage the previously mentioned article and walk through creating an Azure Function App to automatically refresh my Azure Analysis Services model, while correcting a few errors and updating the screenshots.

If you’re new to Azure Analysis Services, take a look at this documentation. For the purposes of this post, I’m going to assume you have a basic understanding of Analysis Services.

Continue reading How to Automate Processing of Azure Analysis Services Models


10 DAX Calculations for your Tabular or Power Pivot Model (Part 2)

This is part two of my 10 DAX Calculations blog series. In this series I’ve blogged ten different DAX calculations you may find useful in your Power Pivot, Tabular or Power BI model. So if you missed part one, I would encourage you to check that out.

Read 10 DAX Calculations for your Tabular or Power Pivot Model (Part 1)

So here’s five more DAX calculations (in no particular order) that I hope you will find useful. Enjoy!

5. DAX Use an Inactive/Custom Relationships in a Calculation

In Tabular and Power Pivot models, you are limited to only one Active relationship between two tables. Often in a relational database you’ll have a role-playing table or a table that is related to another table with more than one foreign-key. A common example of a role-playing table is a Date dimension table since our fact tables often have multiple dates, which is what the following screenshot depicts. We can see that there are two relationships between the Sales and Date tables.


The solid line indicates that this is an Active relationship. The dotted line indicates that relationship is Inactive. In the Manage Relationships window, you can clearly see that one of the relationships is Inactive (highlighted in red). What this means for us is that during slicing, dicing and filtering the Active relationship is used.

The good news is that we can still build calculations that leverage Inactive or unspecified relationships in our model! To do this we can use the USERELATIONSHIP function. This function allows us to specify which columns to relate two tables together.

Here’s an example of a calculation for Total Quantity that uses the relationship highlighted in red in the above screenshot:

Total Quantity by Update Date:=CALCULATE([Total Quantity],USERELATIONSHIP(Sales[UpdateDate],'Date'[Datekey]))


So when we slice the Total Quantity by Update Date calculation by the Date table, the relationship used is the not the default Active relationship as is the case with the Total Quantity measure. We can clearly see this illustrated below in the pivot table:


4. DAX Semi-Additives Measures Opening Period and Closing Period Calculations

Sometimes we have a requirement to create a semi-additive type calculation. If you’re familiar with creating SSAS multidimensional cubes, you’re probably familiar with the concept of semi-additive measure. A semi-additive measure is a measure that is not fully aggregate-able meaning that to find the correct measure amount we cannot aggregate the measure across all time. Consider a measure for account balances or product inventory. If we wish to calculate the current product inventory for the year we must return the inventory on the last day of the year instead of summing the account balances for each day in the year.

There are a couple useful DAX functions we can use to find the opening period balance/inventory or the closing period balance/inventory: FIRSTNONBLANK and LASTNONBLANK.

Here is an example of an opening period type calculation. This calculation will return the first non-blank value in a given date range. Ideally, this will be the product inventory on the first day of the month or year.

Starting Inventory:=CALCULATE([Sum of Inventory], 
FIRSTNONBLANK('Date'[Datekey],[Sum of Inventory]))


And here’s a closing period type calculation. This calculation will return the last non-blank value in a given date range.
Closing Inventory:=CALCULATE([Sum of Inventory], 
LASTNONBLANK('Date'[Datekey],[Sum of Inventory]))


And here’s a sample of the query results:


Now I can easily calculate inventory growth rates!

Inventory Movement:=[Closing Inventory]-[Starting Inventory]


Inventory Movement Percentage:=DIVIDE([Inventory Movement],[Starting Inventory])

Pretty cool stuff!


3. DAX Previous Year, Previous Month, Previous Quarter Calculations

There’s a series of specific DAX functions that I think you’ll find useful for calculating the measures for a previous period:




In part 1 we looked briefly how to calculate the previous MTD calculation, but these functions can also just be used to calculate the previous period metrics and compare the previous period to the current period.

Here’s a couple of examples of using PREVIOUSMONTH and PREVIOUSYEAR to calculate the Starting Inventory for the previous periods:

Previous Month Starting Inventory:=CALCULATE([Starting Inventory],PREVIOUSMONTH('Date'[Date]))


Previous Year Starting Inventory:=CALCULATE([Starting Inventory],PREVIOUSYEAR('Date'[Date]))


In the query results we can now see that we’re able to calculate the previous month and previous year starting inventory amounts. Excellent!


2. DAX First Day of Year, Quarter or Month Inventory/Balance Calculations

The previous examples in this post have all been calculations relative to the level of the Calendar Hierarchy being browsed, but sometimes we just need to calculate the measure on the first day of the year, quarter or month no matter what level we’re browsing. For those situations, we can use the following functions:




Here you can see the calculations for the Year Starting Inventory and Quarter Starting Inventory:

Year Starting Inventory:=CALCULATE([Starting Inventory],STARTOFYEAR('Date'[Date]))


Quarter Starting Inventory:=CALCULATE([Starting Inventory],STARTOFQUARTER('Date'[Date]))


And now we have the Inventory Amounts for the first day of the year or quarter:


1. DAX Rolling Sum and Average Calculations

This type of calculation is easier to set in a multidimensional cube in my opinion but with that said I am more of a cube guy. To get this working, I first created a calculation that sums the total Sales Amount for each day in the past 90 days.

To do this I used the following functions:





And here’s the calculation:

Rolling 90 Day Total Sales Amount:
    = CALCULATE([Total Sales Amount], 
            FIRSTDATE( /* FIRSTDATE gets the first date in this date range which will be 90 days ago */
                DATEADD( /* DATEADD lets me navigate back in time */
                    LASTDATE('Date'[Datekey]) /* This returns the last day no matter if I'm at the day, month or year level */
            LASTDATE('Date'[Datekey]) /* Use the max date for the end date */


Review the comments in the code above to get a better idea of what all the functions are being used for.

Then I created a measure that counts the days that exist within the past 90 days. If the day I’m counting is the first day in my calendar that I have data, I only want to count that one day. This calculation is very similar to the previous calculation except I’m using the COUNTX function to count the rows returned.

Day Count:
    = COUNTX(
    ,[Total Sales Amount])


Now that I have a calculation to get the rolling total sales amount and count the days all I need to do is simply divide the two numbers:

Rolling 90 Day Average Sales Amount:
    =DIVIDE([Rolling 90 Day Total Sales Amount],[Day Count])


And here’s the query results:


Notice that for January the Day Count measure shows only 31. This is because prior to January there’s not data so the Rolling Average is only considering days where data exists. Also notice that the numbers for March and Q1 match since both periods should have the same amount of sales and the same number of days.


10 DAX Calculations for your Tabular or Power Pivot Model (Part 1)

Watch this Power Pivot 101 webinar recording


Let me know your thoughts on these calculations! There’s 100 ways to skin a cat so if you have a different or better way to perform some of these calculations I’d love to see your solution! Thanks for reading! 🙂

Creating Time Calculations in Power BI

One of the current issues in Power BI is the inability to specify a Date table. The Date table is what enables us to create some of the powerful DAX time calculations like Year To Date, Month To Date and more when the Date key is not a Date data type. Ginger Grant has blogged about this issue with a proposed work around, which you can read about here. Even though we can’t exactly specify which table is our Date table in Power BI, that doesn’t mean we can’t create some nifty time calculations with Continue reading Creating Time Calculations in Power BI

Executing DBCC for SQL Server Analysis Services 2016

In the upcoming release of SQL Server Analysis Services 2016, one of the new features you’ll see is the ability to perform a database consistency check against your SSAS cubes and Tabular models. Just like in the database engine side of things, DBCC for SSAS checks for corruption across the entire database or individual objects within the database.

Check out what’s new in SSAS 2016

The DBCC command is shaped likes the XMLA Process command so there’s not a lot of complexity to it. Below here, you can see the basic syntax for the SSAS DBCC command. Its worthing noting that the syntax of the command will look the same whether you’re running it against an SSAS multidimensional database or Tabular model. Continue reading Executing DBCC for SQL Server Analysis Services 2016

10 DAX Calculations for your Tabular or Power Pivot Model (Part 1)

If you’ve read my blog for a while you may have seen the following posts:

Ten MDX Calculations For Your Cube (part 1)
Ten MDX Calculations For Your Cube (part 2)

Well the time has come for me to put together a compilation of ten useful DAX calculations for your Tabular or Power Pivot model (in no particular order so don’t infer any level of ranking or importance from the order they’re posted). Continue reading 10 DAX Calculations for your Tabular or Power Pivot Model (Part 1)

Taking #PowerPivot to the Next Level

Power Pivot is an amazing, flexible and powerful business intelligence tool (among other things) and there is no doubt about that fact. As a feature included with Excel 2013 and 2016 (and an add-on for Excel 2010), Power Pivot allows user with a little technical expertise to integrate disparate data source together within a flexible data model. Once the data is loaded into Power Pivot, we easily have the ability to create powerful calculated measures, key performance indicators Continue reading Taking #PowerPivot to the Next Level

#PowerBI and #SSAS Tabular: A Natural Fit with the Power BI SSAS Connector

SSAS Tabular and Power BI In late June last month, the Microsoft Power BI team released the Microsoft Power BI Analysis Services Connector. The Power BI SSAS Connector allows your deployed Power BI reports to utilize your on-prem SSAS data sources. It’s super easy to set up and can be downloaded for free! And who doesn’t love “free”? Continue reading #PowerBI and #SSAS Tabular: A Natural Fit with the Power BI SSAS Connector