Wednesday, December 9, 2020

DAX - SWITCH / Case

.Class = SWITCH ( TRUE (); ISERROR ( FIND ( "2021"; DIM_directoriesW[FolderFirst2] ) ) <> TRUE (); "Online"; ISERROR ( FIND ( "2018"; DIM_directoriesW[FolderFirst2] ) ) <> TRUE (); "Legacy"; ISERROR ( FIND ( "2019"; DIM_directoriesW[FolderFirst2] ) ) <> TRUE (); "Legacy"; ISERROR ( FIND ( "2020"; DIM_directoriesW[FolderFirst2] ) ) <> TRUE (); "Legacy"; ISERROR ( FIND ( "..."; DIM_directoriesW[FolderFirst2]) ) = TRUE () && ISERROR ( FIND ( "BAG"; DIM_directoriesW[FolderFirst2] ) ) = TRUE (); "???" ) Case1 = IF( SELECTEDVALUE(DimCustomer[EnglishEducation])="Bachelors", "Green", "White") Case2 = SWITCH( SELECTEDVALUE(DimCustomer[EnglishEducation]), "Bachelors","Green", "High School","Red", "Partial High School","Tan", "Graduate Degree","Yellow", "White" ) IF ( [A] > [B], "First case", IF ( [A] = [B], "Second case", IF ( [A] = 0, "Third case", "Fourth case" ) ) ) Case3 = SWITCH( TRUE(), [Sales]>8000000,"Green", [Sales]>5000000,"Tan", [Sales]>3000000,"Yellow", [Sales]<2000000,"Red", "White" ) -- Using SWITCH the first condition met defines the result. -- In the following example, the second condition (<= 150) will never be -- met, because the first one is less restrictive. DEFINE MEASURE Sales[Discounted Sales] = SUMX ( SUMMARIZE ( Sales, Sales[Net Price], Product[Category] ), VAR DiscountPct = SWITCH ( TRUE, Sales[Net Price] <= 1000, 0.2, Sales[Net Price] <= 150, 0.15, Product[Category] = "Audio", 0.13, 0 ) RETURN [Sales Amount] * (1 - DiscountPct ) ) EVALUATE SUMMARIZECOLUMNS ( 'Product'[Category], "Sales Amount", [Sales Amount], "Discounted sales", [Discounted Sales] ) ORDER BY [Category]

No comments:

Post a Comment

Power BI APP - Delete or Unpublish

 UNPUBLISH DELETE