Sector and Geography granularity issue - powerbi

I have a table Time
When the user selects period from february 2020 tç february 2021,I expect to get the following result
But what I get
How to correct the issue with the granularity?
Here is the pbix file https://drive.google.com/file/d/1vf0khr7MbnDTVBzycNgJsaJufwd9F8D_/view?usp=drivesdk

Try this below Measure-
project_wise_time =
SUMX(
SUMMARIZE(
'Table (2)',
'Table (2)'[Project Name],'Table (2)'[DATE],
"distinct_value", DISTINCT('Table (2)'[Time ])
),
[distinct_value]
)
Here is the output-

Related

How can I lock a measure in PBI?

Im working on a dashboard in PBI and I have the next problem...
I have a card that only have to show the month data. For this I use this measure:
Month Orders = CALCULATE(
DISTINCTCOUNT( 'Data'[ORDER] ),FILTER('Data',
'Data'[Month] = 'Data'[Actual Month]),
ALL('Data Incidentes')
)
I understand that if I use All() filter on a measure, this measure don't change when I apply a visual filter but in my case this change.
So my problem is that I have the card that show the month orders but when i apply a visual filter this data change and I don't want it to change.
I hope you understand my problem and my english jaja.
Month Orders = CALCULATE(
DISTINCTCOUNT( 'Data'[ORDER] ),FILTER('Data',
'Data'[Month] = 'Data'[Actual Month]),
ALL('Data Incidentes')
)
Can you try this instead-
Month Orders =
CALCULATE(
DISTINCTCOUNT( 'Data'[ORDER] ),
FILTER(
ALL('Data'),
'Data'[Month] = 'Data'[Actual Month]
)
)

What's wrong with this formula? ( while i'm making KPI)

thisyearsales =
SUMX(
FILTER(
'Sales Transactions',
'Sales Transactions'[year]=2022
),
'Sales Transactions'[value]
)
lastyearsales =
SUMX(
FILTER(
'Sales Transactions',
'Sales Transactions'[year]=2021
),
'Sales Transactions'[value]
)
I don't understand why 'thisyearsales' cause error while 'lastyearsales' work right.
Related tables are below :
Value
Date
Year
10000
2021-01-01
2021
20000
2021-01-02
2021
10000
2021-01-03
2022
I can't reproduce your error. Both measures are working fine for me.
However, I don't see why you are using an iterator function SUMX() when there is nothing to iterate over, while you actually need a function that changes the filter context, like CALCULATE() does:
Last Year Sales =
CALCULATE(
SUM('Sales Transactions'[Value]),
'Sales Transactions'[Year] = 2021
)
This Year Sales =
CALCULATE(
SUM('Sales Transactions'[Value]),
'Sales Transactions'[Year] = 2022
)

DAX max date in dimension ignore filters on date

In my Power BI model I have a fact table (factSales) that links to a date dimension (dimDate) through a surrogate key DateId. Now I want to add a measure to obtain the max invoice date for each client. But it should be the maximum date ignoring the context (for the date filters). (So if I filter all sales in Q1 2020, then I still want the max invoice date in e.g. 2021).
This is how I got it working:
Add new column in factSales:
Invoice Date = RELATED(DimDate[Date])
Add new measure in factSales:
Last Contract =
CALCULATE( MAX(FactSales[Invoice Date]),
ALL( DimDate )
)
This works, but is there a better way to do this ? Without the extra calculated column. (And without using both-directional filtering).
You can use CROSSFILTER inside CALCULATE:
Last Contract =
CALCULATE (
MAX ( Dates[Date] ),
REMOVEFILTERS ( DimDate ),
CROSSFILTER ( Sales[Date], Dates[Date], BOTH )
)
You can create a measure to return max date using the following dax formula:
Measure = MAX(Sheet1[Date])
To always display the latest date without filter by slicer, you need to click on the slicer then goto Format >Edit Interaction >click none on the specific visual. In the following case, the max date is still 8 Nov 21 even though the slicer latest date is Sep 21
Try this:
Last Contract =
CALCULATE ( MAX ( DimDate[Date] ), ALL ( DimDate ), FactSales )
This removes filtering from a slicer on DimDate[Date] by still applies FactSales as a filter table.

How to translate a Tableau FIXED LOD to Power BI?

I have a FIXED LOD with multiple dimensions that looks likes this:
{ FIXED [Customer ID], [Quarter], [Product Type] : SUM([Sales]) }
In Power BI I have wrote it as below using the example given in this article:
CALCULATE(
SUM('Table'[Sales]),
ALLEXCEPT('Table', 'Table'[Customer ID]),
ALLEXCEPT('Table', 'Table'[Quarter]),
ALLEXCEPT('Table', 'Table'[Product Type])
)
However it is not working as expected, could you help me understand the correct way of doing it?
I found the answer by editing my original expression, the following worked as expected:
CALCULATE(
SUM('Table'[Sales]),
ALLEXCEPT('Table', 'Table'[Customer ID], 'Table'[Quarter], 'Table'[Product Type])
)

Eliminating repetitive Storage Engine queries in Power BI

Please see the Power BI model file attached here. I have an Activity table and I'd like to plot on a Line chart, the number of users that were active in the last 365 days as on the date of X Axis.
Hence, I created a date table, but it is not related as the purpose of this table is only to use in the X Axis or date filtering, and all metrics are calculated for the 365 days prior to the date of calculation.
The below DAX formula works, but if analysed in DAX Studio, there is one storage engine query for every date in the X Axis. This is really slow in my actual model file and I am looking for help optimising it.
Active Users =
var latestDate = MAX('Calendar'[Date])
RETURN
CALCULATE(
DISTINCTCOUNT('Activity Details'[Group User ID]),
ALL('Calendar'[Date]),
'Activity Details'[Event Date] <= latestDate,
'Activity Details'[Event Date] >= (latestDate - 365)
)
EDIT
The following DAX formula queries storage engine only once, but spends way more time in formula engine.
Active Users =
var latestDate = MAX('Calendar'[Date])
RETURN
CALCULATE(
SUMX(
SUMMARIZE(
'Activity Details', 'Activity Details'[Group User ID],
"Last Event", MAX('Activity Details'[Event Date])
),
1
),
ALL('Calendar'[Date]),
'Activity Details'[Event Date] <= latestDate,
'Activity Details'[Event Date] >= (latestDate - 365)
)