I have two columns Month and ID a want distinc count per each month, but once I use data slicer to show data it shows as count distinct per select period
For example I have
I have
I used :
COUNT_ID = distinctcount('ID'[DATA])
once I select in data slicer 202207 & 202208 I get distinct values 4:
WANT
but I want result 5 because
202207 distinct values 2
202208 distinct values 3
I want to use this logic for whole data set once I select specific period.
Has anybody can help with?
Ids =
SUMX (
VALUES ( 'Table'[Month] ),
CALCULATE ( DISTINCTCOUNT ( 'Table'[ID] ) )
)
Related
I have one requirement where I need to overwrite the filter context using All key word in Power bi Dax
In the table there are two value columns: Sales and Purchase and one date column .My calculation is based on these column
Simply dividing Sales by Purchase .But there are many attributes column with text values I want to remove the filter context for Purchase calculation .My data will look like below
My Dax formula looks like this:
measure_name =
CALCULATE (
SUM ( table_name[Sales] ),
YEAR ( table_name[Date of entry] ) = MAX ( YEAR ( table_name[Date of entry] ) )
)
/ CALCULATE (
SUM ( table_name[Purchase] ),
YEAR ( table_name[Date of entry] ) = MAX ( YEAR ( table_name[Date of entry] ) ),
ALL ( table_name[Attribute1] ),
ALL ( table_name[Attribute2] ),
ALL ( table_name[Attribute3] )
)
here I have put all attributes in the dax simply putting coma which will throw error
Any one can help me how to write this .Only for purchase(denominator calculation ) I want to remove the filter for any number of attribute columns.Or is there any other way to do this calculation .This data is dummy data .In future if we are getting more attributes , can we pass one list for this All parameters .So that user will just update in the excel all attributes and when it get refreshed , these parameter values to pass in to this All parameter automatically..?
i need to calculate the distinct count of panel names based on distinct vehicle no's
ex: for 6073kxx vehicle -distinct count of panels are 7 . please provide a dax calculation for this. this is sample data I have more vehicle numbers.
Just create a measure to do the distinctcount on the other column.
Create a measure:
Distinct Count of Panels = DISTINCTCOUNT('your Table name here'[Vehicle No])
Try this measure
Measure =
SUMX ( VALUES ( 'Table'[Vehicle No] ), DISTINCTCOUNT ( 'Table'[panel name] ) )
I want to show the consolidated data for similar record in separate column in power bi data.
I have a data with two columns and i want the result like below in third & fourth column
3rd column result nothing but comparing unique id in rows, e.g. 1=2 =false, 2=2=true
4th column result nothing but concatenation of Value column for unique record
could you please help to achieve this in power bi - i want to create custom columns for these two result in data table
We can use CalculatedColumn in DAX:
Result =
CALCULATE(
CONCATENATEX (
CALCULATETABLE ( VALUES('Unique'[Value] ) ),
'Unique'[Value],
", ",
'Unique'[Value],
ASC
), ALL('Unique'[Value])
)
And you Validation may be a measure:
Valid = if(SELECTEDVALUE('Unique'[Value]) = CALCULATE( max('Unique'[Value]), ALL('Unique'[Value])), FALSE(), TRUE())
My intention is to populate days of the month to simulate a data warehouse periodic snapshot table using DAX measures. My goal is to show non-additive values for the quantity.
Consider the following transactions:
The granularity of my snapshot table is day. So it should show the following:
Take note that a day may have multiple entries but I am only interested in the latest entry for the day. If I am looking at the figures using a week period it should show the latest entry for the week. It all depends on the context fixter.
However after applying the measure I end up with:
There are three transactions. Two on day 2 and the other on day 4. Instead of calculating a running total I want to show the latest Qty for the days which have no transactions without running accumulating totals. So, day 4 should show 4 instead of summing up day 3 and day 4 which gives me 10. I've been experimenting with LASTNONBLANK without much success.
This is the measure I'm using:
Snapshot =
CALCULATE(
SUM('Inventory'[Quantity]),
FILTER(
ALL ( 'Date'[Date] ),
'Date'[Date] <= MAX( 'Date'[Date] )
)
)
There are two tables involved:
Table # 1: Inventory table containing the transactions. It includes the product id, the date/time the transaction was recorded and the quantity.
Table # 2: A date table 'Date' which has been marked as a date table in Power BI. There is a relationship between the Inventory and the Date table based on a date key. So, in the measure, 'Date'[Date] refers to the Date column in the Date table.
You can use the LASTNONBLANKVALUE function, that returns the last value of the expression specified as second parameter sorted by the column specified as first parameter.
Since LASTNONBLANKVALUE implicitly wraps the second parameter into a CALCULATE, a context transition happens and therefore the row context is transformed into the corresponding filter context. So we also need to use VALUES to apply the filter context to the T[Qty] column. The returned table is a single row column and DAX can automatically convert a single column, single row table to a scalar value.
Then, since we don't have a dimension table we have to get rid of cross-filtering, therefore we must use REMOVEFILTERS over the whole table.
the filter expression T[Day] < MaxDay is needed because LASTNONBLANKVALUE must be called in a filter context containing all the rows preceding and including the current one.
So, assuming that the table name is T with fields Day and Qty like in your sample data, this code should work
Edit: changed in order to support multiple rows with same day, assuming the desired result is the sum of the last day quantities
Measure =
VAR MaxDay =
MAX ( T[Day] )
RETURN
CALCULATE (
LASTNONBLANKVALUE (
T[Day],
SUM ( T[Qty] )
),
T[Day] <= MaxDay,
REMOVEFILTERS ( T )
) + 0
Edit: after reading the comments, this might work on your model (untested)
Measure =
VAR MaxDay =
MAX ( 'Date'[Date] )
RETURN
CALCULATE (
LASTNONBLANKVALUE (
Inventory[RecordedDate],
SUM ( Inventory[Quantity] )
),
'Date'[Date] <= MaxDay
) + 0
I have a running total dax measure that works. Problem now is that the slicer on the page is coming from another data set which is linked to the source table of running total data set and when you select the slicer it doesn't filter anything.
Homes Connected =
CALCULATE (
SUM ( refv_FTTH_HomesConnected[ActualHomesConnected] ),
FILTER ( ALL ( refv_FTTH_HomesConnected ), refv_FTTH_HomesConnected[Month_sort2] <= MAX ( refv_FTTH_HomesConnected[Month_sort2] ) )
)
Is there a way to incorporate the columns from the other dataset to get the desired result?
The ALL in your FILTER removes any slicer selection filtering.
Try using ALLSELECTED instead.