









Studia grazie alle numerose risorse presenti su Docsity
Guadagna punti aiutando altri studenti oppure acquistali con un piano Premium
Questa pagina non è visibile nell’anteprima
Non perderti parti importanti!










ALL( [ | [, [, [,…]]]] ) Returns all the rows in a table, or all the values in a column, ignoring any filters that might have been applied. This function is useful for clearing filters and creating calculations on all the rows in a table. DATE(, , ) Returns the specified date in datetime format. DISTINCTCOUNT() Counts the number of distinct values in a column. DIVIDE(, [,]) Performs division and returns alternate result or BLANK() on division by 0.
RELATED() Returns a related value from another table. SUM() Adds all the numbers in a column. SUMX(, ) Returns the sum of an expression evaluated for each row in a table. USERELATIONSHIP(,) Specifies the relationship to be used in a specific calculation as the one that exists between columnName1 and columnName2.
Selling Days How to find the number of selling days : ✅CalendarYear ✅Revenues Selling Days= DISTINCTCOUNT (Sales[OrderDate])
We don’t have a clear indication of when we were open, so we do a proxy. So, let’s assume that if we were open, at least we received an order.
AND – OR AND (&&) and OR (||) are two logical operators that allow us to verify the simultaneous holding of multiple things. Compute the revenues with 3 conditions that must be true at the same time :
The formula calculates the total sales amount for all orders made by female customers with a bachelor's degree in the year 2001:
Revenues to F Customers OR (in 2001 AND to Bachelors)= SUMX ( FILTER( Sales, RELATED(Customer[Gender]=”F” || (RELATED(,Calendar’[CalendarYear])=2001 && RELATED(Customer[EnglishEducation])=”Bachelors”) ), Sales[UnitPrice]*Sales[OrderQuantity] )
The code is the same as before, the only thing that changes is that we substituted the second || with &&. Moreover, we put the 6th^ and the 7th^ line in brackets ().
Intro to CALCULATE CALCULATE is useful to simplify our calculations. It allows us to make a calculation modifying a basic measure. Let’s check the basic measure “Revenues” : ✅Color ✅Revenues Revenues= --SUM(Sales[SalesAmount]) SUMX( Sales, Sales[UnitPrice]*Sales[OrderQuantity] )
ALL Revenues CALCULATE= CALCULATE( [Revenues], ALL ( Sales ) )
In this case we removed all the filters with “ ALL ( Sales ) ”, but we added a new one: Customer[Gender]=”F ”.
CALCULATE multiple OR Transform the following formula into a CALCULATE formula. Revenues to F Customers OR in 2001 OR to Bachelors= SUMX ( FILTER( Sales, RELATED(Customer[Gender]=”F” || RELATED(,Calendar’[CalendarYear])=2001 || RELATED(Customer[EnglishEducation])=”Bachelors” ), Sales[UnitPrice]*Sales[OrderQuantity] ) ✅Color ✅Revenues We cannot turn it into CALCULATE because we don’t know how to make an OR between columns of different tables. Calculate the total revenue earned from sales to female customers OR customers with a bachelor's degree (with SUMX and CALCULATE). ✅Color ✅Revenues SUMX Revenues to F Cust OR Bachelors= SUMX( FILTER(
Sales, RELATED(Customer[Gender])=”F” || RELATED(Customer[EnglishEducation])=”Bachelors” ), Sales[UnitPrice]*Sales[OrderQuantity] ) CALCULATE Revenues F Cust OR Bachelors CALCULATE= CALCULATE( [Revenues], Customer[Gender]=”F” || Customer[EnglishEducation])=”Bachelors” )
In the CALCULATE version the two filters Customer[Gender]=”F” and Customer[EnglishEducation])=”Bachelors” must be in the same row. We can also add other filters (columns) if they’re from the same Customer table.
Rename Revenues and call it Revenue (Orders). ✅CalendarYear ✅Revenues Create a new relationship between Date and Ship Date, keeping active the relationship between Date and Order Date.
Generate a formula that calculate the total revenue based on the ship date of orders. Remember to make active the relationship between Date and Ship Date. ✅CalendarYear ✅Revenues (Orders) Shippings= CALCULATE( [Revenues (Orders)], USERELATIONSHIP( Sales[Ship Date], ‘Calendar’[Date] ) )