Snippets Collections
Sales % =

DIVIDE (
	[Total Sales],
	CALCULATE (
		[Total Sales],
		ALLSELECTED ( 'Product'[Brand])
		)
)
LY Sales 2 =

CALCULATE( 
	[Total Sales],
	SAMEPERIODLASTYEAR( 'Calendar'[Date] )
	)
LY Sales 1 =

SUMX ( 
	SAMEPERIODLASTYEAR( ' Calendar'[Date] ),
	[Total Sales]
	)
Sales-LWTD = 

CALCULATE(
    [Sales-WTD],
    FILTER( 
        ALL( 'Calendar'),
        'Calendar'[Week Rank] = MAX( 'Calendar'[Week Rank] )-1 
        )
)
Sales-LWTD = 

CALCULATE( [Total Sales]), 
	FILTER( ALL( 'Calendar'),
	'Calendar'[Week Rank] = ( MAX ('Calendar'[Week Rank]) -1) && 
	'Calendar'[Weekday] <= < MAX( 'Calendar'[Weekday])
		)
	)
Sales-WTD = 

CALCULATE( [Total Sales], 
	FILTER( ALL('Calendar'),
		'Calendar'[Week Rank] = MAX( 'Calendar'[Week Rank] ) && 
		'Calendar'[Weekday] <= MAX( 'Date'[Weekday] ) 
		) 
	)
Sales-PW =

CALCULATE ( [Total Sales], 
	FILTER( ALL( 'Calendar' ),
	'Calendar'[Week Rank] = MAX ( 'Calendar'[Week Rank] ) -1 ) 
	)
Week Number = 

WEEKNUM( [Date], 2 )
Week End date = 

'Calendar'[Date] + 7-1 * WEEKDAY( 'Calendar'[Date], 2 )
Week Start date = 

'Calendar'[Date] + -1 * WEEKDAY( 'Calendar'[Date], 2 ) + 1
Sales-WTD = 

VAR CD =
    LASTDATE( 'Calendar'[Date] )

VAR CY =
    MAX( 'Calendar'[Year] )
    
VAR WeekDayNo =
    WEEKDAY( LASTDATE( 'Calendar'[Date] ), 3 )

RETURN
CALCULATE(
    [Total Sales],
    DATESBETWEEN(
        'Calendar'[Date],
        DATEADD(
            CD, 
            -1 * WeekDayNo, DAY ), 
            CD),
    'Calendar'[Year] = CY
)
Sales-WoW% = 

VAR WoW =
    [Sales-WoW]
    
VAR PW = 
    [Sales-PW]
    
RETURN
    IF (
        PW = BLANK (),
            BLANK (),
        DIVIDE ( WoW, PW )
        )
Sales-WoW = 

VAR WoW =
    IF ( [Sales-PW] = BLANK(),
        BLANK(),
    [Sales-CW] - [Sales-PW] )

RETURN
    WoW
Sales-PW = 

VAR CurrentWeek =
    SELECTEDVALUE( 'Calendar'[WeekNo] )

VAR CurrentYear =
    SELECTEDVALUE( 'Calendar'[Year] )

VAR MaxWeekNo =
    CALCULATE(
        MAX ( 'Calendar'[WeekNo] ), 
            ALL ( 'Calendar' )
            )

RETURN
SUMX(
    FILTER( ALL ( 'Calendar' ),
        IF ( CurrentWeek = 1,
            'Calendar'[WeekNo] = MaxWeekNo && 'Calendar'[Year] = CurrentYear -1,
            'Calendar'[WeekNo] = CurrentWeek -1 && 'Calendar'[Year] = CurrentYear )
        ),
    [Total Sales]
    )
Sales-CW = 

CALCULATE( [Total Sales], 
    FILTER(
        ALL('Calendar'),
        'Calendar'[Week Rank] = MAX( 'Calendar'[Week Rank])
            )
        )
Sales-DoD% = 

VAR DoD =
    [Sales-DoD]
    
VAR PD = 
    [Sales-PD]
    
RETURN
    IF (
        PD = BLANK (),
            BLANK (),
        DIVIDE ( DoD, PD )
        )
Sales-DoD = 

VAR DoD =
    IF ( [Sales-PD] = BLANK(),
        BLANK(),
    [Total Sales] - [Sales-PD] )

RETURN
    DoD
Sales-PD =

CALCULATE( 
    [Total Sales],
    DATEADD( 'Calendar'[Date], -1, DAY )
    )
Sales Rep Rank =

RANKX(
	ALL( Sales[Sales Rep]),
	[Total Sales],
	Dense
)

//Dense = not skip
Table =

{
	("Nik", 101),
	("Hafiz", 102),
}
Table =

DATATABLE(
	"SNo", INTEGER,
	"Name", STRING,
	{
		{101, "Nik"},
		{102, "Hafiz"},
	}
)
Best Selling Day/Date =

CONCATENATEX(
	TOPN(
		1,
		'Calendar',
		[Total Sales]
		),
	FORMAT( 'Calendar'[Date], "dd-mmm" )
	)
Top Selling Product =

TOPN(
	1,
	VALUES( Sales[ProductID] ),
	[Total Sales]
)
Best Selling Day/Date =

TOPN(
	1,
	'Calendar',
	[Total Sales]
)
Qtr =

SWITCH(
	TRUE(),
	MONTH('Calendar[Date]') <=3, "Q1",
	MONTH('Calendar[Date]') <=6, "Q2",
	MONTH('Calendar[Date]') <=9, "Q3",
	"Q4"
)
YearWeekNo = 

'Calendar'[Year]*100 + 'Calendar'[WeekNo]
WeekNo = 

"W" & WEEKNUM( 'Calendar'[Date], 2 )
Week Rank = 

RANKX(
    ALL( 'Calendar' ),
    'Calendar'[Week StartDate], , ASC, Dense)
Week StartDate = 

'Calendar'[Date] + -1*WEEKDAY( 'Calendar'[Date], 2 ) + 1
Week EndDate = 

'Calendar'[Date] + 7-1*WEEKDAY( 'Calendar'[Date], 2 )
Calendar = 
  
VAR CalTable = CALENDARAUTO ()
VAR MyCal =
    ADDCOLUMNS (
        CalTable,
        "Index", MONTH ( [Date] ),
        "Month", FORMAT ( [Date], "mmm" ),
        "Qtr", FORMAT ( [Date], "\QQ" ),
        "Year", FORMAT ( [Date], "yyyy" )
    )
RETURN
    MyCal
LOOKUPVALUE(
    Products[UnitPrice],
    PRODUCTS[ProductID], ORDER_DETAILS[ProductID]
        )
CALCULATE(
    [Revenue],
    FILTER(
        ALL( 'Calendar'[Year] ),
        'Calendar'[Year] IN { 1996, 1998 }
    )
)
Earliest Date

= #date(Date.Year(List.Min(Source[OrderDate])),1,1)

Latest Date

= #date(Date.Year(List.Max(Source[RequiredDate])),12,31)

(Dynamic) Calendar
let
    Source = {Number.From(pmEarliestDate)..Number.From(pmLatestDate)},
    #"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    #"Renamed Columns" = Table.RenameColumns(#"Converted to Table",{{"Column1", "Date"}}),
    #"Changed Type" = Table.TransformColumnTypes(#"Renamed Columns",{{"Date", type date}})
in
    #"Changed Type"
foreach (var m in Model.AllMeasures) {
  m.Description = m.Expression;
}
star

Sat Dec 30 2023 07:22:38 GMT+0000 (Coordinated Universal Time)

#ms.pbi #dax #dax.calculate #dax.filter #dax.all #dax.max
star

Sat Dec 30 2023 07:12:45 GMT+0000 (Coordinated Universal Time)

#ms.pbi #dax #dax.weekday
star

Sat Dec 30 2023 07:11:01 GMT+0000 (Coordinated Universal Time)

#ms.pbi #dax #dax.weeknum
star

Sat Dec 30 2023 07:07:22 GMT+0000 (Coordinated Universal Time)

#ms.pbi #dax #dax.weekday
star

Sat Dec 30 2023 07:06:37 GMT+0000 (Coordinated Universal Time)

#ms.pbi #dax #dax.weekday
star

Sat Dec 30 2023 04:43:03 GMT+0000 (Coordinated Universal Time)

#ms.pbi #dax #previous.day #dax.calculate #dax.dateadd
star

Tue Dec 26 2023 07:58:24 GMT+0000 (Coordinated Universal Time)

#ms.pbi #dax #dax.ranks #dax.all #ranking
star

Tue Dec 26 2023 03:29:11 GMT+0000 (Coordinated Universal Time)

#ms.pbi #dax #table
star

Tue Dec 26 2023 03:28:03 GMT+0000 (Coordinated Universal Time)

#ms.pbi #dax #dax.datatable #dax.integer #dax.string #table
star

Mon Dec 25 2023 14:05:21 GMT+0000 (Coordinated Universal Time)

#ms.pbi #dax #dax.topn #ranking #dax.format #dax.concatenatex
star

Mon Dec 25 2023 13:57:48 GMT+0000 (Coordinated Universal Time)

#ms.pbi #dax #dax.topn #ranking #dax.values
star

Mon Dec 25 2023 13:55:40 GMT+0000 (Coordinated Universal Time)

#ms.pbi #dax #dax.topn #ranking
star

Sun Dec 24 2023 07:39:01 GMT+0000 (Coordinated Universal Time)

#ms.pbi #dax #calendar.table #dax.switch #dax.true #dax.month #quarter
star

Mon Dec 18 2023 02:38:12 GMT+0000 (Coordinated Universal Time)

#ms.pbi #dax #calendar.table #week.no
star

Mon Dec 18 2023 02:37:06 GMT+0000 (Coordinated Universal Time)

#ms.pbi #dax #calendar.table #dax.day
star

Mon Dec 18 2023 02:33:17 GMT+0000 (Coordinated Universal Time)

#ms.pbi #dax #dax.weekday #calendar.table
star

Mon Dec 18 2023 02:30:50 GMT+0000 (Coordinated Universal Time)

#ms.pbi #dax #calendar.table #dax.format #dax.calendar #format-ddd
star

Mon Dec 18 2023 02:25:30 GMT+0000 (Coordinated Universal Time)

#ms.pbi #dax #calendar.table #dax.weeknum
star

Mon Dec 18 2023 02:23:35 GMT+0000 (Coordinated Universal Time)

#ms.pbi #dax #calendar.table #dax.weekday
star

Mon Dec 18 2023 02:22:15 GMT+0000 (Coordinated Universal Time)

#ms.pbi #dax #calendar.table #dax.weekday
star

Mon Dec 18 2023 02:18:56 GMT+0000 (Coordinated Universal Time)

#ms.pbi #dax #calendar.table #dax.quarter
star

Fri Dec 08 2023 09:49:57 GMT+0000 (Coordinated Universal Time)

#ms.pbi #dax #dax.lookupvalue
star

Thu Dec 07 2023 09:25:10 GMT+0000 (Coordinated Universal Time) https://www.ehansalytics.com/blog/2019/3/17/create-a-dynamic-date-table-in-power-query

#ms.pbi #power.query #date #earliest.date #ms.excel
star

Wed Nov 04 2020 01:25:15 GMT+0000 (Coordinated Universal Time) https://youtu.be/Wkap4yZmO9M

#dax #tabular.editor #live.dataset #ms.pbi #dataset

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension