Docsity
Docsity

Prepara i tuoi esami
Prepara i tuoi esami

Studia grazie alle numerose risorse presenti su Docsity


Ottieni i punti per scaricare
Ottieni i punti per scaricare

Guadagna punti aiutando altri studenti oppure acquistali con un piano Premium


Guide e consigli
Guide e consigli


Guida alle Funzioni DAX: Sintassi, Uso e Contesto di Filtro - Prof. Bergamaschi, Schemi e mappe concettuali di Computer Graphics

Una panoramica concisa delle funzioni dax (data analysis expressions) utilizzate in power bi e altri strumenti di analisi dati. Esplora concetti chiave come il contesto di filtro, le funzioni calculate, all, filter e removefilters, offrendo esempi pratici e spiegazioni dettagliate. Il documento include anche esempi di misure di base e avanzate, utili per calcolare vendite, margini di contribuzione e altre metriche aziendali. È una risorsa utile per chiunque voglia approfondire l'uso di dax per l'analisi dei dati.

Tipologia: Schemi e mappe concettuali

2022/2023

In vendita dal 28/10/2025

AnastasiaAngeli
AnastasiaAngeli 🇮🇹

16 documenti

1 / 11

Toggle sidebar

Questa pagina non è visibile nell’anteprima

Non perderti parti importanti!

bg1
COMPUTATIONAL TOOLS SUMMARY
FORMULAS
COUNTROWS: it returns the number of rows in the table that you specify.
1. DISTINCTCOUNT: it returns the number of distinct values of the column you specify.
1. CALCULATE
1. It resets the filter context (therefore, applying it may lead you to have a column
with all the same result as the one filtered)
1. If a filter is already present, the filter will override the filter with the new one
1. ALL shows the number of all the rows without filters
1. It takes a table and create another table as output, that is the entire table (without
any filter)
2. ALL is used within CALCULATE as one of the filters in order to remove the
filter context
1. Useful to compute PCT (percentages %) PCT month net sales = Net sales
/ALL m. net sales
1. FILTER applies a selection (select but the others are still visible, do not filter)
1. FILTER does not really filter the table, but rather it just selects the rows that we
want to consider (so it does not alter the filter context)
2. Possible to use it in CALCULATE to have the function operating on a subset of
the table (not in all the rows of the current filter context)
1. FILTER is an integrator (goes row by row in a table)
1. REMOVEFILTERS
1. si può usare al posto di ALL
2. rather than creating a new table, it just removes all the filters that are active
1. KEEPFILTERS leave all the filters active
1. KEEPFILTERS changes the overwrite behaviour of
CALCULATE: CALCULATE does not create a new temporal filter context, it
keeps the existing one (particularly evident when the filter is applied on the same
column)
2. Generally better to use CALCULATE (FILTER (table) ALL (column))) because,
by doing so, we are filtering only one column (and not the entire table) =
less process cost when using millions of data
1. RELATED to take a column from another table
2. RELATEDTABLE to select from another table
1. DATEADD to see values from the previous year, month, or day
1. VALUE takes a column and return a table with one column that shows only the
visible values (it is affected by the filter)
1. DIVIDE, SUMX (allows to directly use column)
pf3
pf4
pf5
pf8
pf9
pfa

Anteprima parziale del testo

Scarica Guida alle Funzioni DAX: Sintassi, Uso e Contesto di Filtro - Prof. Bergamaschi e più Schemi e mappe concettuali in PDF di Computer Graphics solo su Docsity!

COMPUTATIONAL TOOLS SUMMARY

FORMULAS

  • COUNTROWS : it returns the number of rows in the table that you specify.
  1. DISTINCTCOUNT : it returns the number of distinct values of the column you specify.
  2. CALCULATE
  3. It resets the filter context (therefore, applying it may lead you to have a column with all the same result as the one filtered)
  4. If a filter is already present, the filter will override the filter with the new one
  5. ALL shows the number of all the rows without filters
  6. It takes a table and create another table as output, that is the entire table (without any filter)
  7. ALL is used within CALCULATE as one of the filters in order to remove the filter context
  8. Useful to compute PCT (percentages %) – PCT month net sales = Net sales /ALL m. net sales
  9. FILTER applies a selection (select but the others are still visible, do not filter)
  10. FILTER does not really filter the table, but rather it just selects the rows that we want to consider (so it does not alter the filter context)
  11. Possible to use it in CALCULATE to have the function operating on a subset of the table (not in all the rows of the current filter context)
  12. FILTER is an integrator (goes row by row in a table)
  13. REMOVEFILTERS
  14. si può usare al posto di ALL
  15. rather than creating a new table, it just removes all the filters that are active
  16. KEEPFILTERS leave all the filters active
  17. KEEPFILTERS changes the overwrite behaviour of CALCULATE: CALCULATE does not create a new temporal filter context, it keeps the existing one (particularly evident when the filter is applied on the same column)
  18. Generally better to use CALCULATE (FILTER (table) ALL (column))) because, by doing so, we are filtering only one column (and not the entire table) = less process cost when using millions of data
  19. RELATED to take a column from another table
  20. RELATEDTABLE to select from another table
  21. DATEADD to see values from the previous year, month, or day
  22. VALUE takes a column and return a table with one column that shows only the visible values (it is affected by the filter)
  23. DIVIDE , SUMX (allows to directly use column)
  1. Never use a measure in SUMX, just use operations with columns within the measure of SUMX
  2. IF (condition, true, false) used to label neg, pos or good. (use max 2 if in each formula)
  3. HASONEVALUE allows to see only single value results. Same as COUNTRAWS(values(column)=1)
  4. Possible to use || (or) or && (and) to add filters. When using || in CALCULATE, it can be used only in the same column (not possible to add filter coming from another column by using ||)

MEASURES

  1. Average selling price ASP = SALES / QUANTITY
  2. (Weighted ASP = sum sales / sum quantity)
  3. Selling days = DISTINCTCOUNT (invoice date)
  4. PLT10 transactions= COUNTROWS (filter (invoice shipments, invoice shipments=PLT10))
  5. PLT10 transactions calculate= CALCULATE (transaction, filter (invoice shipments, invoice shipments=PLT10))
  6. ALL SALES =SUMX (ALL (invoice shipments), (invoice shipments [sales]))
  7. Variable cost amt = unit var cost * quantity
  8. Contribution margin CM amount = sales amt - variable costs amt (if it is <0 --> loss)
  9. Contribution margin CM PCT = CM amt / sales amt
  10. Sum of CM pct = sum CM amt / sum sales amt
  11. Variable cost = sales – CM amt
  12. Sale changes % = (sales/ sales previous year)/ sales previous year
  13. IF (HASONEVALUE....) to hide the grand total

FILTER CONTEXT AND FILTER TRANSMISSION

By connecting the different tables with arrows, it is possible to create an automatic VLOOKUP that creates interconnection between the tables (they are called filter transmission wires )

MEASURES BASIC DATASET

Sales = SUMX( 'Invoiced Shipments', 'Invoiced Shipments'[Quantity]'Invoiced Shipments'[Unit Price USD] ) ALL Sales = SUMX( ALL ('Invoiced Shipments'), 'Invoiced Shipments'[Quantity]'Invoiced Shipments'[Unit Price USD] ) ALL Sales CALCULATE = CALCULATE( [Sales], REMOVEFILTERS('Invoiced Shipments') ) ALL PLT10 Sales = SUMX( FILTER( ALL('Invoiced Shipments'), 'Invoiced Shipments'[Production Plant]="PLT10" ), 'Invoiced Shipments'[Quantity]*'Invoiced Shipments'[Unit Price USD] ) ALL PLT10 Sales CALCULATE = CALCULATE( [Sales], FILTER( ALL('Invoiced Shipments'), 'Invoiced Shipments'[Production Plant]="PLT10" ) ) ALL PLT10 Sales CALCULATE REMOVEFILTER = CALCULATE( [Sales], 'Invoiced Shipments'[Production Plant]="PLT10", REMOVEFILTERS('Invoiced Shipments') ) Transactions = COUNTROWS('Invoiced Shipments') ALL Transactions = COUNTROWS( ALL( 'Invoiced Shipments' ) ) Transactions % = DIVIDE( [Transactions], [ALL Transactions] )

ALL PLT10 Transactions = COUNTROWS( FILTER( ALL ( 'Invoiced Shipments' ), 'Invoiced Shipments'[Production Plant]="PLT10" ) ) Active Customers = DISTINCTCOUNT('Invoiced Shipments'[Cust No]) Selling Days = DISTINCTCOUNT('Invoiced Shipments'[Invoice Date]) QTY = SUM('Invoiced Shipments'[Quantity]) Average Selling Price = DIVIDE ( [Sales], [QTY] ) Average Sale per Transaction = DIVIDE( [sales], [Transactions] ) Average Sale per Customer = DIVIDE( [sales], [Active Customers] ) Products Sold = DISTINCTCOUNT('Invoiced Shipments'[Product]) PLT10 Sales = SUMX( FILTER( 'Invoiced Shipments', 'Invoiced Shipments'[Production Plant]="PLT10" ), 'Invoiced Shipments'[Quantity]*'Invoiced Shipments'[Unit Price USD] ) PLT10 Sales CALCULATE = CALCULATE( [Sales], 'Invoiced Shipments'[Production Plant]="PLT10" )

PLT10 OR EURO Transactions CALCULATE = CALCULATE( [Transactions], FILTER( 'Invoiced Shipments', 'Invoiced Shipments'[Production Plant]="PLT10" || RELATED(Customers[Salesarea])="EURO" ) )

MEASURES ADVANCED DATA SET

Sales = SUMX( Sales, Sales[UnitPrice]*Sales[OrderQuantity] ) Sales Cust Iter = SUMX( Customer, [Sales] ) Sales PY (Per Year)= IF( HASONEVALUE('Calendar'[CalendarYear]), CALCULATE( [Sales], DATEADD('Calendar'[Date],-1,YEAR) ) ) Sales YOY Pct = DIVIDE( [Sales]-[Sales PY], [Sales PY] ) Transactions = COUNTROWS(Sales) Customer Transaction = COUNTROWS(Sales) Customer Transactions Works = COUNTROWS( RELATEDTABLE(sales) ) Customer Transaction Mystery = CALCULATE( [Transactions], 'Calendar'[CalendarYear]= ) Trendy Color Sales = CALCULATE( [Sales], KEEPFILTERS( 'Product'[Color] IN {"Black", "Blue", "Red", "Silver"} ) )

CALCULATE (Expression/MeasureName; [Filter1]; [Filter2]; … ; [FilterN]) - steps

  1. evaluation of all filters (if any), in the starting filter context. The evaluation consists in establishing the allowed values for the columns of the tables involved in the filters (the CALCULATE filters are always tables, ALWAYS) and in keeping them in memory, they will be applied only in point 4
  2. context transition, if CALCULATE was called in a row context, turning the row context into an equivalent filter context and then killing the row context (or in nested row contexts, in this case all of them will be killed and turned into an equivalent filter context)
  3. application to the new filter context, created with the context transition of point 2, of the modifiers (if any): ALL functions (ALLSELECTED, ALL, ALLEXCEPT, ALLNOBLANKROW), CROSSFILTER, USERELATIONSHIPS, REMOVEFILTERS)
  4. application to the new filter context (created with the context transition of point 2 and the modifiers of point 3) of the filters evaluated in point 1, possibly with KEEPFILTERS which is a filter modifier and not a CALCULATE modifier. The filters must all apply simultaneously in the new filter context. If one of the filters concerns a column that has already been filtered (for example by having a column that is part of the filters in a pivot/matrix), then the existing filter is removed and replaced with the one indicated in the CALCULATE formula, otherwise the filter is added
  5. evaluation, in the new filter context, of the first argument (a DAX expression or the name of a DAX measure)

RIPASSO Revenues sumx Quantity sum Average Selling Price revenues/quantity Number of Transactions countrows Average sale per transaction revenues/transactions Active Customers distinctcount Average sale per customer revenues/customers Selling days distinctcount Average sale per selling day revenues/days All Transactions countrows(all( Pct of Transactions in each country with respect to ALL transactions transactons/all transa P1 Transactions countrows(filter(…=…)) ALL P1 Transactions countrows(filter(all(…=…)) ALL Revenues sumx(all( P1 Revenues sumx(filter( ALL P1 Revenues sumx(filter(all( TT1 Revenues sumx(filter Canada Revenues sumx(filter(…related( F Revenues sumx(filter(…related( F Canada Revenues sumx(filter(…(related 1 && related 2 F Canada Revenues in 2001 sumx(filter(…(related 1 && related 2 && related 3 F OR Canada Revenues sumx(filter(…(related 1 || related 2 ALL THE FORMULAS WITH CALCULATE