I am trying to write a measure that will allow me to filter on statuscode and Datesbetween. With the filter, plus the two conditions, I have too many arguments for the FILTER function. What syntax can I use to get the desired result?
Won-Existing =
SUMX (
FILTER ( _enquiries,
_enquiries[_GUID] = _2018_Budget[_GUID] &&
_enquiries[statuscode] = 866120005 &&
DATESBETWEEN(_enquiries[Date Contract Awarded],DATE(2018,8,1),DATE(2018,8,31)
),
_enquiries[Amount (Enq)]
))
Looks like some parentheses mismatching to me. Try this:
Won-Existing =
SUMX (
FILTER ( _enquiries,
_enquiries[_GUID] = _2018_Budget[_GUID] &&
_enquiries[statuscode] = 866120005 &&
DATESBETWEEN(_enquiries[Date Contract Awarded], DATE(2018,8,1), DATE(2018,8,31))
),
_enquiries[Amount (Enq)]
)
Related
I'd like to know how to write this line bellow in DAX. I'm a beginner and I'm having a lot of problems trying to write this code in Dax to return the value I need.
(select
top 1 Payor.CompanyName
from Payor, PatientPayor
where PatientPayor.PatientSer = pat.PatientSer
and Payor.PayorSer = PatientPayor.PayorSer) as conv,
This is what I tried to do so far.
Convenio =
TOPN ( 1, VALUES ( Payor[CompanyName] ), PatientPayor[PatientSer] )
= FILTER ( Patient, PatientPayor[PatientSer] = Patient[PatientSer] )
I did solve it with the code bellow:
formula =
VAR currpayorSer =
SELECTEDVALUE ( PatientPayor[PayorSer] )
VAR currPatientSer =
SELECTEDVALUE ( PatientPayor[PatientSer] )
RETURN
CALCULATE (
MIN ( Payor[CompanyName] ),
FILTER ( ALLSELECTED ( Payor ), Payor[PayorSer] = currpayorSer ),
FILTER ( ALLSELECTED ( Patient ), Patient[PatientSer] = currPatientSer )
)
I have some problem with the HR Dashboard, where I can't get it to work properly.
I have the following visuals:
Visual for HR Dashboard
The headcount code is as follow:
Headcount = CALCULATE (
DISTINCTCOUNT ( FactTable[EmpID]),
FILTER ( ALL(FactTable), FactTable[EmploymentStatus] = "Active" )
)
The problem is, that the visual doesn't slice on the seniority.
Need help.
I have try with some sample data, i guess the issue here is due to you are using filter function, you can try my method if the problem can be solved:
1)I have this original sample table
I have created a measure to count the total employee still with company
Total count = CALCULATE(COUNT(Sheet1[ID]),Sheet1[Status] = "active")
3)My scorecard has displayed the total count correct for with junior slicer
First its bad maner to write code like this:
CALCULATE (
DISTINCTCOUNT ( FactTable[EmpID] ),
FILTER (
ALL ( FactTable ),
AND (
FactTable[DateofHire] <= MIN ( 'Kaldt funktion'[Date] ),
OR (
FactTable[DateofTermination] = BLANK (),
FactTable[DateofTermination] >= MAX ( 'Kaldt funktion'[Date] )
)
)
)
)
A good practice is to use ALL with columns that you really need in your filter. Second instead of comparing column = BLANK() use function ISBLANK(Table[ColumnName]). You also should compare SELECTEDVALUE to get the correct data. (unfortunately, you don't post any samples, and I don't know how your data looks like I can only guess). How is correlated 'Kaldt funktion' with FactTable? Probably problem is in your MIN and MAX. We can also use && insted of AND, and || insted of OR;
CALCULATE (
DISTINCTCOUNT ( FactTable[EmpID] ),
FILTER (
ALL ( FactTable[DateofHire], FactTable[DateofTermination] ),
SELECTEDVALUE ( FactTable[DateofHire] ) <= MIN ( 'Kaldt funktion'[Date] )
&& (
ISBLANK ( FactTable[DateofTermination] )
|| SELECTEDVALUE ( FactTable[DateofTermination] ) >= MAX ( 'Kaldt funktion'[Date] )
)
)
)
I have Users table containing user_email, user_name, user_category.
The following DAX filter returns a table:
FILTER(Users,[User_Email] = userprincipalname())
I want to get the user_category.
1 approach is SELECTEDCOLUMNS( FILTER(Users,[User_Email] = userprincipalname()), "User_category", [User_Category] ). This returns the result as a column.
Is there any alternate approach to return just 1 value? For example:
SELECTEDVALUE ( SELECTEDCOLUMNS( FILTER(Users,[User_Email] = userprincipalname()), "User_category", [User_Category] ) )
OR
VALUES ( SELECTEDCOLUMNS( FILTER(Users,[User_Email] = userprincipalname()), "User_category", [User_Category] ) )
You can use MAXX on the table generated by FILTER.
MAXX(
FILTER(Users,[User_Email] = userprincipalname()),
[User_Category]
)
You can do this with CALCULATE assuming you don't expect there to be multiple values to choose from (if there are, this will return a blank).
CALCULATE (
SELECTEDVALUE ( Users[User_Category] ),
FILTER ( Users, Users[User_Email] = userprincipalname() )
)
I've been trying to get the sum of the following table's column VALUE using DaxStudio in order to put that on PowerBI once is's ok, since PBI can get slow if you test a code for large calculated tables.
Table from DaxStudio
BU VALUE
------------------------
FOODS 0.0000
FIBI 0.0000
GEOS/CIS 0.7300
CASC
S_S
SGS
COCOA
COCOA/SSSA
CORPORATE
N/A
CIS
The code behind it:
DEFINE
VAR TOTAL =
CALCULATE (
SUMX (
PACKAGING_POWERBI_YEARLY_2;
PACKAGING_POWERBI_YEARLY_2[QUANTIDADE_ANTERIOR]
);
FILTER (
PACKAGING_POWERBI_YEARLY_2;
PACKAGING_POWERBI_YEARLY_2[DATE] = "2018"
&& PACKAGING_POWERBI_YEARLY_2[CODIGO] = "43130"
)
)
EVALUATE
SUMMARIZE (
CALCULATETABLE (
FILTER (
PACKAGING_POWERBI_YEARLY_2;
PACKAGING_POWERBI_YEARLY_2[PRECO_PONDERADO] <> BLANK ()
&& PACKAGING_POWERBI_YEARLY_2[PRECO_PONDERADO] <> 0
)
);
PACKAGING_POWERBI_YEARLY_2[BU];
"VALUE"; FORMAT (
(
CALCULATE (
SUMX (
PACKAGING_POWERBI_YEARLY_2;
PACKAGING_POWERBI_YEARLY_2[QUANTIDADE_ANTERIOR]
);
FILTER (
PACKAGING_POWERBI_YEARLY_2;
PACKAGING_POWERBI_YEARLY_2[DATE] = "2018"
&& PACKAGING_POWERBI_YEARLY_2[CODIGO] = "43130"
&& PACKAGING_POWERBI_YEARLY_2[PRECO_PONDERADO] <> BLANK ()
)
) / TOTAL
)
* (
CALCULATE (
SUMX ( PACKAGING_POWERBI_YEARLY_2; PACKAGING_POWERBI_YEARLY_2[PRECO_PONDERADO] );
FILTER (
PACKAGING_POWERBI_YEARLY_2;
PACKAGING_POWERBI_YEARLY_2[DATE] = "2018"
&& PACKAGING_POWERBI_YEARLY_2[CODIGO] = "43130"
&& PACKAGING_POWERBI_YEARLY_2[PRECO_PONDERADO] <> BLANK ()
)
)
);
"0.0000"
)
)
Instead of generating the table I would like to sum the results of column VALUE, but the only way I got to plot a result without error is through a "CALCULATED TABLE" (above).
Every filter I try leads to an error.
The idea is to get just the sum of that calculated column VALUE:
0.7300
But every simpler filter or SUMX condition I try, an error pops-up.
I'd think you could clean it up to look something like this:
CALCULATE (
SUMX (
VALUES ( PACKAGING_POWERBI_YEARLY_2[BU] ),
SUM ( PACKAGING_POWERBI_YEARLY_2[QUANTIDADE_ANTERIOR] )
/ CALCULATE (
SUM ( PACKAGING_POWERBI_YEARLY_2[QUANTIDADE_ANTERIOR] ),
ALL ( PACKAGING_POWERBI_YEARLY_2[BU] )
)
* SUM ( PACKAGING_POWERBI_YEARLY_2[PRECO_PONDERADO] )
),
FILTER (
PACKAGING_POWERBI_YEARLY_2,
PACKAGING_POWERBI_YEARLY_2[DATE] = "2018"
&& PACKAGING_POWERBI_YEARLY_2[CODIGO] = "43130"
&& PACKAGING_POWERBI_YEARLY_2[PRECO_PONDERADO] <> BLANK ()
&& PACKAGING_POWERBI_YEARLY_2[PRECO_PONDERADO] <> 0
)
)
This uses SUMX to iterate through each of the BU values and for each one, calculates the value
(QUANTIDADE_ANTERIOR / Total QUANTIDADE_ANTERIOR ) * PRECO_PONDERADO
where the filters are reused instead of repeated.
I can't guarantee that this code works exactly as intended, but it should point you in a better direction.
How do I add a AND to my SUMX() statement? My current code is:
Enquiry Excluded Amt =
SUMX (
FILTER ( _enquiries, _enquiries[_GUID] = _2018_Budget[_GUID] ),
_enquiries[Amount (Enq)]
)
But I want an AND statement added into the SUMX()
Enquiry Excluded Amt =
SUMX (
FILTER ( _enquiries, _enquiries[_GUID] = _2018_Budget[_GUID] ),
_enquiries[Amount (Enq)] AND _enquiries[Excluded] = TRUE()
)
The above doesn't work.
The syntax && allows for combining conditions in a filter. Like this, for example:
Enquiry Excluded Amt =
SUMX (
FILTER ( _enquiries,
_enquiries[_GUID] = _2018_Budget[_GUID] && _enquiries[Excluded] = TRUE()
),
_enquiries[Amount (Enq)]
)