How do I fix this lookup value formula error? - powerbi

I received this error:
A table of multiple values was supplied where a single value was expected
I'm trying to pull in multiple contract status' (Next 7, Next 15, Next 30, Next 90, Next 120, Next 180, > 180 and Expired) and return them to the site master table you see below.
These status are flowing over as a formula, from the contract end date, on Sales Force Contract Status
Here is the formula:
Z - Status Flag = LOOKUPVALUE('Sales Force_Contract'[Z - Contract Status],'Sales Force_Contract'[Z Sage ID],viw_SiteMaster[JobNo])
What am I doing wrong?

I ended up trying this formula:
Z - Status Flag = calculate(FIRSTNONBLANK('Sales Force_Contract'[Z - Contract Status], 1),
filter(all('Sales Force_Contract'),
'Sales Force_Contract'[Z Sage ID] = viw_SiteMaster[JobNo]))
and it worked! It had to do with blanks.
I feel like alot of my errors have to do with blanks.
Thanks team!

Related

Calculate the difference between 2 rows in PowerBI using DAX

I'm trying to complete something which should be quite simple but for the life of me, I can't work it out.
I'm trying to calculate the difference between 2 rows that share the same 'Scan type'.
I have attached a photo showing sample data from production. We run a scan and depending on the results of the scan, it's assigned a color.
I want to find the difference in Scan IDs between each Red scan.
Using the attached Photo of Sample data, I would expect a difference of 0 for id 3. A difference of 1 for id 4 and a difference of 10 for id 14.
I have (poorly) written something that works based on the maximum value from the scan id.
I have also tried following a few posts to see if I can get it to work..
var _curid= MAX(table1[scanid])
var _curclueid = MAX(table1[scanid])
var _calc =CALCULATE(SUM(TABLE1[scanid],FILTER(ALLSELECTED(table1[scanid]),table1[scanid]))
return if(_curid-_calc=curid,0,_curid-_calc)
Edit;
Forgot to mention I have checked threads;
57699052
61464745
56703516
57710425
Try the following DAX and if it helps then accept it as the answer.
Create a calculated column that returns the ID where the colour is Red as follows:
Column = IF('Table'[Colour] = "Red", 'Table'[ID])
Create another column as following:
Column 2 =
VAR Colr = 'Table'[Colour]
VAR SCAN = 'Table'[Scan ID]
VAR Prev_ID =
CALCULATE(MAX('Table'[Column 2]),
FILTER('Table', 'Table'[Colour] = Colr && 'Table'[Scan ID] < SCAN))
RETURN
'Table'[Column] - Prev_ID
Output:
EDIT:-
If you want your first value(ID3) to be 0 then relace the RETURN line with the following line:
IF(ISBLANK(Prev_ID) && 'Table'[Colour] = "Red", 0, 'Table'[Column] - Prev_ID )
This will give you the following result:

Circular dependency while calculating column

I have a single table of data named RDSLPDSL. I am trying to calculate two columns based on two measures I am creating from the table.
Count of RDSL Marker for 1 =
CALCULATE(
COUNT('RDSLPDSL'[RDSL Marker]),
'RDSLPDSL'[RDSL Marker] IN { 1 }
)
I am using the above code as a measure to look for values only with 1 in it in the RDSL Marker column.
RDSL % = DIVIDE([Count of RDSL Marker for 1], COUNTROWS(RDSLPDSL))
Then I created a column using the above code to divide the rows with 1 by the total number of rows in the table.
I am doing the same for another column with PDSL. It is as follows:
Count of PDSL Marker for 1 =
CALCULATE(
COUNT('RDSLPDSL'[PDSL Marker]),
'RDSLPDSL'[PDSL Marker] IN { 1 }
)
PDSL % = DIVIDE([Count of PDSL Marker for 1], COUNTROWS(RDSLPDSL))
But when I do this calculation, I am getting an error for circular dependency detected and not getting the final output even though the same code worked for the previous column.
I tried COUNTAX directly instead of using CALCULATE but that brings up the same error too.
I also tried using measures instead of custom column which seems to remove the error but the output is not what I expect and is incorrect.
Any help for the same would be highly appreciated.

How to fix error "404" in Power BI M query

I am getting error code 404 in PowerBI.
Sample Data:
ID, text
1, #VirginAmerica What #dhepburn said.
2, #VirginAmerica plus you've added commercials to the experience..
3, #VirginAmerica I didn't today... Must mean I need to take another
4, "#VirginAmerica it's really aggressive to blast obnoxious ""entert
5, #VirginAmerica and it's a really big bad thing about it
I am trying to write sentiment score in PowerBI using M query in Microsoft cognitive services.
below is my query.
Query: (Source as table) as any =>
let JsonRecords = Text.FromBinary(Json.FromValue(Source)),
JsonRequest = “{“”documents””: ” & JsonRecords & “}”,
JsonContent = Text.ToBinary(JsonRequest, TextEncoding.Ascii),
Response =
Web.Contents(“https://westcentralus.api.cognitive.microsoft.com/text/analytics”,
[
Headers = [#”Ocp-Apim-Subscription-Key”= APIkey,
#”Content-Type”=”application/json”, Accept=”application/json”],
Content=JsonContent
]),
JsonResponse = Json.Document(Response,1252)
in
JsonResponse (Query end)
Error:
An error occurred in the ‘’ query. DataSource.Error: Web.Contents failed to get contents from 'https://vizguru.cognitiveservices.azure.com/text/analytics/v2.1/sentiment/keyPhrases' (404): Resource Not Found
Details:
DataSourceKind=Web
DataSourcePath=https://vizguru.cognitiveservices.azure.com/text/analytics/v2.1/sentiment/keyPhrases
Url=https://vizguru.cognitiveservices.azure.com/text/analytics/v2.1/sentiment/keyPhrases
Expected Output:
ID, text, Score,
1, #VirginAmerica What #dhepburn said., 2
2, #VirginAmerica plus you've added commercials to the experience..., 3
3, #VirginAmerica I didn't today... Must mean I need to take another !,4
4, #VirginAmerica it's really aggressive to blast, 5
5, #VirginAmerica and it's a really big bad thing about it, 6
Steps Followed from this link.
Please suggest a solution.
Thanks,
Shiva
Yes, I can repro your 404 error on my side . The reason is the text analysis endpoint:
https://westcentralus.api.cognitive.microsoft.com/text/analytics
not works anymore .
If you want to use azure cognitive service text analytics API, pls refer to this guide to find correct endpoint and ways to call text analysis service .
If you have any further concerns ,pls feel free to let me know .

How to fix "Query returns and empty value" error in google spread sheet

I have the following code. I've read many threads on how to solve query returning empty value but none of them worked in my case.
I've also shared a workaround Google spreadsheet.
What I'm going to do is that search first tab by query and if it matched, show a green tick, otherwise show a red cross.
The code below works for green tick but in case of red cross, it shows an error.
How the code below is expected to operate:
It makes a query on tab1 and if student number is in column C (with some defined conditions) OR is in column D (without any condition), it shows a green tick, otherwise, it must insert a red cross.
if(OR(QUERY(LiveAttendanceForm!$A:$C,
"select C
where A >= timestamp '"&TEXT(D$1, "yyyy-MM-dd HH:mm:ss")&"'
and A <= timestamp '"&TEXT(D$2, "yyyy-MM-dd HH:mm:ss")&"'
and C = "&$C5, 0)=$C5,Query(LiveAttendanceForm!$A:$D,"select D where D = "&$C5,0)=$C5),"✅","❌")
I also tried using iferror function before the query, but it shows all fields as true and makes all cells green tick. I'll be very grateful if someone can help me fix this annoying issue! The share Google sheet's link is below:
https://docs.google.com/spreadsheets/d/1KfkA48OyOnZAPQAbtdEIs9AYaAPRFRFOpvQRM5QyPss/edit?usp=sharing
you will need to wrap your queries into IFERROR:
=IF(OR(IFERROR(QUERY(LiveAttendanceForm!$A:$C,
"select C
where A >= timestamp '"&TEXT(D$1, "yyyy-MM-dd HH:mm:ss")&"'
and A <= timestamp '"&TEXT(D$2, "yyyy-MM-dd HH:mm:ss")&"'
and C = "&$C4, 0))=$C4,
IFERROR(QUERY(LiveAttendanceForm!$A:$D,
"select D
where D = "&$C4, 0))=$C4), "✅", "❌")

How to get Date between two Dates Django

I need to check is there any object exist for given time Interval? How can I do that?How can I translate this Mysql into Django:
SELECT *
FROM `event_event`
WHERE (startDate BETWEEN "2010-10-1" AND "2010-10-5")
OR (endDate BETWEEN "2010-10-1" AND "2010-10-5")
I am currently using
Event.objects.filter(Q(startDate__range(datetime(2010,10,1),datetime(2010,10,5)))|Q(endDate__range(datetime(2010,10,1),datetime(2010,10,5))))
But I am not getting any object when I am using Django filter.Please suggest me where I am wrong.
Do
print Event.objects.filter(Q(startDate__range(datetime(2010,10,1),datetime(2010,10,5)))|Q(endDate__range(datetime(2010,10,1),datetime(2010,10,5)))).query
And see what SQL it produces, it'll help you spot the differences.
Try To Do This:
Event.objects.filter(Q(startDate >= datetime(2010, 10, 1), startDate <= datetime(2010, 10, 5)) | Q(endDate >= datetime(2011, 10, 1), endDate <= datetime(2010, 10, 5)))