March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now
Hi Guys, need help in writing a DAX query to create a Table view in Power BI
As you can see above, I have a Table - which has cities and dates with Sales count, I want to create a view with single record per city and sales count of all its occurrences in that week ending on Saturday.
So far i have written this ('Data Sheet' is the name of the excel I am reading data from ...)
WeeklySalesCount =
ADDCOLUMNS(
GENERATE(
DataSheet,
DATESBETWEEN(
CALENDAR(MIN(DataSheet[Date]), MAX(DataSheet[Date])),
[Date] - WEEKDAY([Date], 2) + 1,
[Date] - WEEKDAY([Date], 2) + 7
)
),
"Location", InvIssue[Location],
"Sales", InvIssue[Sales]
)
but power gives me error saying, it cannot find this column date: Any other idea, as how to create this table using a DAX measure???
Solved! Go to Solution.
Hi,
Please check the below picture and the attached pbix file.
New Table =
VAR _wknumber =
ADDCOLUMNS ( Data, "@wknumber", WEEKNUM ( Data[Date], 1 ) )
VAR _wkendingdate =
ADDCOLUMNS (
_wknumber,
"@wkendingdate", MAXX ( FILTER ( _wknumber, [@wknumber] = EARLIER ( [@wknumber] ) ), Data[Date] )
)
RETURN
GROUPBY (
_wkendingdate,
Data[Location],
[@wkendingdate],
"@Sales", SUMX ( CURRENTGROUP (), Data[Sales] )
)
If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.
Bizarre that your 1 Apr, 2023 is Sunday ...
Anyway, it's easy enough to solve by PQ
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("ddLLDcMgDAbgXThHKjamwLEpW0TZf42mtPIjhhv6ZP2yjY8j7GEL8Ij0wIjpeqcUzu0I/cYIg7/VqKvblBHn/Kt+XU/SHAe/71y4OiumyNl53rdmTJzddDVxNkTtRaaPfs7hZi2Zm4Hkc7wTt2P8v4Lu6rM4+WlHjhm3LjzJvE/vu/MmOcZJ+pnUj/zi++l3T/K3ULXDwuVErJeFqyuui7mav7XuPHM/aO6hLlzyjav9I8znNa7+BSf31p1f+zk/", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Loc = _t, Date = _t, Qty = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Loc", type text}, {"Date", type date}, {"Qty", Int64.Type}}),
Sorted = Table.Sort(#"Changed Type",{{"Loc", Order.Ascending}, {"Date", Order.Ascending}}),
#"Grouped by Week" = Table.Group(Sorted, {"Loc","Date"}, {"Grp", each [Weekly = List.Sum([Qty]), Saturday = Date.ToText(Date.EndOfWeek([Date]{0},Day.Sunday), "ddd dd/MM/yyyy")]}, 0, (x,y) => Byte.From(Date.WeekOfYear(x[Date],Day.Sunday)<>Date.WeekOfYear(y[Date],Day.Sunday))),
#"Expanded Grp" = Table.RemoveColumns(Table.ExpandRecordColumn(#"Grouped by Week", "Grp", {"Saturday","Weekly"}), "Date")
in
#"Expanded Grp"
Equally easy by DAX
Expertise = List.Accumulate( {Days as from Today}, {Skills and Knowledge}, (Current, Everyday) => Current & Day.LeanAndPractise(Everyday) ) |
Hi,
Please check the below picture and the attached pbix file.
New Table =
VAR _wknumber =
ADDCOLUMNS ( Data, "@wknumber", WEEKNUM ( Data[Date], 1 ) )
VAR _wkendingdate =
ADDCOLUMNS (
_wknumber,
"@wkendingdate", MAXX ( FILTER ( _wknumber, [@wknumber] = EARLIER ( [@wknumber] ) ), Data[Date] )
)
RETURN
GROUPBY (
_wkendingdate,
Data[Location],
[@wkendingdate],
"@Sales", SUMX ( CURRENTGROUP (), Data[Sales] )
)
If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
23 | |
16 | |
12 | |
9 | |
7 |
User | Count |
---|---|
38 | |
32 | |
29 | |
12 | |
11 |