missing values from sameperiodlastyear in powerpivot - dax

Greeting. I am new to DAX.
This is what I got...
[img]https://i.ibb.co/8YsMVpV/A91-B5-FF1-569-B-4-B99-B3-C7-A3510-AE0-A798.jpg[/img]
This is what I want...
[img]https://i.ibb.co/TMqP1cW/B264458-C-BA48-4204-885-F-30-D41-DBB7754.jpg[/img]
The problem I have now is missing "Other-COT" sales from MTD LY. Everything is good (including the shop total) except "Other-COT" is not showing in my pivot table.
I guess the reason is MTD data has no Other-COT sales for shop ABC and MTD LY is bounded by MTD's season filter.
Highly appreciate if someone could help me or could give me a clue.
Below are my formulas,
Sales Net = sum(SALES[NetSales])
Sales Net MTD = CALCULATE([Sales Net],DATESMTD('Calendar'[Date]))
Sales Net MTD LY = CALCULATE([Sales Net MTD],SAMEPERIODLASTYEAR('Calendar'[Date]),FILTER(all(SALES),SALES[Date]>=STARTOFMONTH('Calendar'[Date])&&SALES[Date]<=DATEADD(STARTOFMONTH(SALES[Date]),DAY(MAX(SALES[Date]))-1,DAY)),KEEPFILTERS(Season_Master),KEEPFILTERS(Shop_Master))
And I have 2 slicers selecting Year and Month.
Million Thanks
James
Data Model

Related

Advanced Filter on PowerQuery

Question
I am trying to filter some excel data I have on PowerQuery but am really struggling to figure out the best way to do this. On Excel I would usually do this using an Advanced Filter but I don't believe Power Query has the same functionality.
I would like to filter across a number of columns, using an OR condition for a:
a range of values in some columns; and
a range of 'wild card' searches in other columns
Example
As an example if my dataset is as below
Name
Function
Sub-Function
Position
Country
Andy
Sales
Omni-Channel
Sales Manager
Brazil
Bob
Marketing
eCommerce
Web Design
Argentina
Rakesh
HR
Business Partnering
HRBP
Italy
Tom
Finance
Reporting
Finance Manager
UK
Chris
Sales
Trade Marketing
Sales support
US
Raj
Legal
Legal
Para-legal
Brazil
I might want to filter for anyone meeting the following criteria;
working in the sales function OR
working in the Trade Marketing or Omni-Channel sub-function OR
has the words 'Manager' or 'Sales' in their Position title OR
is based in Brazil
The desired output would then be
Name
Function
Sub-Function
Position
Country
Andy
Sales
Omni-Channel
Sales Manager
Brazil
Tom
Finance
Reporting
Finance Manager
UK
Chris
Sales
Trade Marketing
Sales support
US
Raj
Legal
Legal
Para-legal
Brazil
My current approach
My approach was to create a table which had all my criteria (not including the 'wild card' searches), upload to PowerQuery, create multiple lists from this table (called for example Filter1, Filter2 etc..). Then using the following formula against my main dataset
= Table.SelectRows(#"Filtered Rows1", each (List.Contains(Filter1,[Function]) = true) or (List.Contains(Filter2,[Sub-Function]) = true) or (List.Contains(Filter3,[Country]) = true) or Text.Contains([Position], "Manager") or Text.Contains([Position], "Sales"))
Issues
The formula above works for really small data sets however not on my 80,000 line data set, or rather it does not work within a reasonable time frame
I have a long list of 'wild card' searches which apply to three columns so typing in the Text.Contain(...... etc.. formula multiple times into the formula seems very inefficient, is prone to mistakes and is not dynamic in any way.
I'm sure there must be a better way to do this but I have not found many helpful discussions or tutorials on this online so am reaching out to the community.
Thank you
I think the part of the problem the query is slow as with your current approach, filtering is evaluating filtering conditions separately before it could filter. Power bi is capable of handling filter on multiple columns in a single filter, like following
Table.SelectRows(
#"Changed Type1",
each ([Function] = "Sales")
or ([#"Sub-Function"] = "Trade Marketing" or [#"Sub-Function"] = "Omni-Channel")
or (
Text.Contains([Position], "Manager")
or Text.Contains([Position], "Sales")
or ([Country] = "Brazil")
)
)

In Dax, how can I get value from multiple columns with multiple criteria?

I am just a beginner in Dax language.
I googled it a lot to find solution, but failed.
Please help me to solve this problem.
Here are the two tables examples and there is no relation between them. ( I am using power query and power pivot)
I need to get sales location visitor from another table.
enter image description here
enter image description here
Branch
Date
Item
QTY
Sales Location
Visitor
USA.
2021.01.01
A.
23
1st floor
????
Canada
2021.01.02
B.
44
2nd floor
????
Date
USA's 1st floor visitor
USA's 2nd floor visitor
Canada's 1st floor visitor
Canada's 2nd floor visitor
2021.01.01
5435
664
2342
4532
2021.01.02
5345
345
2234
342
I tried to use IF and Lookupvalue, but it shows errors.
Could you please help me?
Thank you in advance.
You'll need to use Power Query to do some transformations to the second table so that it looks like this:
To do this, you'll have to transpose all columns, fill down the country column, and unpivot all other columns (highlight all other columns > unpivot columns). I'd then recommend adding a column to both tables that unites the country and sales location (USA-1st floor, USA-2nd floor, etc.) to both tables and use that as your connection in the model. You'll then be able to do a VLOOKUP using this united column between the tables.
Someone else may have a quicker answer but this should get you there!

Deactivating a filter applied to a card in POWER BI

Rank Turnover =
RANKX(
ALL(Regions[Region]),
CALCULATE([Sales Total],KEEPFILTERS(Sales[Currency]="EUR"))
)
Hi everyone, got stuck with this one for the second day in a row. There are 3 tables in a dataset (Regions, Sales and Currency). Regions and Currency are filtering out the Dashboard when applied. My Intention is to have Total Sales in a Card for EUR only for a Chosen in a Region Filter Country. Everything works fine, but whenever I choose "LC" (Local Currency) in Currency Filter, the numbers Change - I Need to overcome that. Changing LC in that Filter should not affect Total Sales, they have to still be done in EUR.
Any help will be appreciated,
Thank you
Rank Sales EUR =
RANKX(
ALL(Regions[Region]),
CALCULATETABLE(
{[Sales Total]},
TREATAS({"EUR"}, 'Dashboard Currency'[Currency]),FILTER(Dates, Dates[Year]=MAX([Year]))))
Here is the answer. Thank you all for support

dax handling summary values in a matrix report

Source data columns are Store, Product, StoreSales, and ProductSales
StoreSales has duplicate values, even across different Stores.
Looking for a dax measure to handle StoreSales as described in the image.
This is the closest so far, but doesn't account for duplicates between stores.
Store Sales:=
sumx(DISTINCT(_Sales[StoreSales), _Sales[StoreSales])
screenshot of source and pivot table
To answer your question directly, this formula should give you the desired result:
Desired Result for Store Sales =
IF(ISFILTERED(_Sales[Store]), SUM(_Store[Store Sales]))
However, I recommend to revisit your data model design. It's conceptually incorrect (you are mixing detailed data with the summary of the same data), and you will have serious problems with DAX. A better way to structure your data:
Remove column "Store Sales". It's redundant and does not fit the data level of detail.
Rename column "Product Sales" into "Sale Amount". It's just sale amount, without any qualifiers.
Create a measure "Total Sales" = SUM(_Sales[Sale Amount]). It will correctly calculate total sales both on product and store levels.
If you need a special measure for store sales, use SUMX:
Store-level sales = SUMX (VALUES(_Sales[Store]), [Total Sales])
And if you need to show product contributions to store sales:
Product Contribution = `DIVIDE([Total Sales], [Store-Level Sales])

DAX - YTD with year on columns

Can anybody suggest how to write YTD Sales formula in DAX that can be used (e.g. in Excel Pivot Table) with Year on column, to compare YTD sales over the last few years.
Specifically, my difficulty is in determining "as of date". If I refer to the Date table without removing the filter, then something like LASTNONBLANK('Date'[Date],[SalesAmount]) will give me 12/31 of the corresponding year for prior year's columns. And if I remove the Date filter via ALL() I will get the last available date, thus ignoring filters/slicers a user may have added.
I am fairly new to DAX, and was hoping that this was a common scenario that someone has already solved. But all I am finding are the solutions for YTD comparison with prior year, NOT YTD "trend" over multiple years.
Any feedback is really appreciated!
Vlad
You need to provide more details for me to be specific, but I can guess at your dataset.
Assuming:
table1 with Date, Period, Year and SalesAmount
AND
table2 with Period and Year
AND
No relationships.
Your measures might go like this:
MAX_PERIOD = CALCULATE(MAX(table2[Period]))
MAX_YEAR = CALCULATE(MAX(table2[Year]))
YTD Sales = Calculate(Sum([SalesAmount]), FILTER(table1, table1[Period] <= [MAX_PERIOD] && table2[Year] = [MAX_YEAR]))
And your Pivot Table/Matrix might look like this:
_____________________________
|Filters: |Columns: |
| |table2[Period]|
| | |
|____________|______________|
|Rows: |Values: |
|table2[Year]|[YTD Sales] |
_____________________________

Resources