Error in Tableau when creating a calculated field with variables from two datasets - datasource

I have two datasets: one with thousands of rows that has information about clients (one row per client) and more than 100 variables; and another one which is the result of a Machine Learning process that has some important values of the top 10 most important client's variables (one row per variable).
I want to create a chart that displays the variable in the first dataset that has the highest value in the second dataset. The variables in the second dataset are:
[Dataset]: is a variable that is the same for all the dataset, and is used to fix a calculation (string).
[Variables]: is a list with the names of the most important variables (string).
[Correlation With Target]: is the correlation between the variable in that row and a target variable (float).
This are the calculations that I have made. The first calculated field is created in the second dataset, and the other two calculated fields are created in the first dataset.
Highest Correlation:
IF ABS([Correlation With Target])=={ FIXED [Dataset]:MAX(ABS([Correlation With Target]))} THEN [Variables] ELSE null END
Variable Number:
CASE ATTR([Sheet1 (Variable Dataset)].[Highest Correlation])
WHEN "Borrower Age" THEN 1
WHEN "Credit score - Borrower" THEN 2
WHEN "Monthly Disposable Income" THEN 3
WHEN "Loan Term" THEN 4
WHEN "LTV" THEN 5
WHEN "Monthly Interest Rate" THEN 6
WHEN "Outstanding Principal Balance" THEN 7
WHEN "Years at Address" THEN 8
WHEN "Years in Employment" THEN 9
END
Correlation Graph:
IF {[Highest Correlation]=1} THEN [Borrower Age]
ELSEIF {[Highest Correlation]=2} THEN [Credit Score]
ELSEIF {[Highest Correlation]=3} THEN [Income]
ELSEIF {[Highest Correlation]=4} THEN [Loan Term]
ELSEIF {[Highest Correlation]=5} THEN [LTV]
ELSEIF {[Highest Correlation]=6} THEN [Interest Rate]
ELSEIF {[Highest Correlation]=7} THEN [Outstanding Principal Balance]
ELSEIF {[Highest Correlation]=8} THEN [Years at Address]
ELSEIF {[Highest Correlation]=9} THEN [Years in Employment]
END
The problem is that in the 3rd calculation, when calling the [Highest Correlation] field, it throws this error:
"All fields in a level of detail expression must came from the same datasource"
What would be the turn around for this problem?
PS: I can't share the workbooks or data, but I will answer any question related to it so I can help you to help me.

I think the problem is that field [Income] comes from a different datasource.
If it is posible you post Datasources and Fields?

Related

calculate unique identifier for record comparison

I have a table that stores imported data. Upon each import I need to check if an imported item already exists. I use a unique ID for this and it works fine. BUT the reason for the match could be that the same record is being imported (there are no controls on date ranges for the creation of import data), or the data may actually have been amended.
So my issue is that to see which type it is I was planning to run a calc on the 11 currency fields that this record has. I can't just add them up since the amendment of one field (say an increase of 10, would reduce another by 10). I thought of Field1 x1 + Field2 x2 etc. which should remove the dependency.
This isn't really a vba issue but more of a data uniqueness issue I think.
Of course I could compare 11 values but that is messy in VBA! Any ideas welcome. Many thanks.
Data example
Record in current database:
Receipt Payment DealValue Tax Duties etc
3,500 0 3,600 100 0
//3,600 - 100 = 3,500 net receipt
Importing record
Receipt Payment DealValue Tax Duties etc
3,500 0 3,650 150 0
//3,650 - 150 = 3,500 net receipt
I'm don't wish to create an ID, just a calc that can be compared to see if there is a change.
In the looping approach you would do something along the following lines:
firstColumnOfInterestIndex = ...
lastColumnOfInterestIndex = ...
duplicate = False
...
For Each currentRow In ActiveSheet
For i=firstColumnOfInterestIndex to lastColumnOfInterestIndex
If Worksheet.Cells(currentRow.Row, i) <> expectedValue(i) Then
Exit For
End If
If i == lastColumnOfInterestIndex Then
' A duplicate found! handle accordingly
duplicate = True
End If
Next i
If duplicate Then
Exit For
End If
Next currentRow

Most efficient way to check if a number is within a large amount of ranges in vba

I am attempting to code what sounds like either a segment or interval tree, but I'm not sure how to do it in VBA. Basically, what I am trying to do is take a list of numbers and seeing if they fall under a list of ranges. In the real world, the numbers refer to customers, and these ranges are assigned to different company sites. So for example, let's say we had 3 numbers (aka customers) to input: 156000 166000 and 256000. Site 1 gets any customers between 145000 and 149000, 152300 to 155000, and 165000 to 165999. Site 2 gets any customers between 156000 and 159000, 162000 and 165000, and 255000 to 275000. Site 3 get any customers between 166000 to 180000. So I would want the function to be able to tell that customer one and three would go to site 2, and customer two would go to site three. So each site has about one to eight nonconsecutive ranges associated with it.
The amount of numbers(customers) being checked against ranges can vary from 1 to 5000, but the amount of ranges is about 3000 spread across 497 different sites, which will slowly increase over time but will be statically updated. Customer numbers will be copy/pasted to column K in my Excel worksheet. The site ranges I will have in another sheet in the same workbook. Initially I tried to just do tons of if/then statements, but it seems like doing a list of 3000 if/then statements cant be the best way. Then I thought about doing a tiered list of if/then statements, by initially just looking at the first two numbers of the customer number stored in column L, like:
If Worksheets("Input").Range("L" & x) >= 14 and _
If Worksheets("Input").Range("L" & x) =< 19 then
If Worksheets("Input").Range("K" & x) >= 145000 and _
If Worksheets("Input").Range("K" & x) >= 146000 then
[code to assign customer to specific site]
End If
If Worksheets("Input").Range("K" & x) >= 245000 and _
If Worksheets("Input").Range("K" & x) >= 246000 then
[code to assign customer to specific site]
End If
End If
The problem with doing it this way is that each site has non consecutive ranges, so I'm not sure if making multi tiered if/then statements would even be able to work.
Anyone have any ideas as to how this could efficiently be done with such a large amount of ranges?
Thanks in advance!
This is very easy to do using VLookup (Range) combined with a smaller conditional test to ensure the empty spaces between ranges don't pass. No VBA needed:

Exception from HRESULT: 0x800A03EC in VB.net writing to excel

I'm aware there are other questions similar to this, but I haven't found an answer that works for me. I have a program that writes an excel report for sales by month. It works fine when given a date range less than three years, but when I input a date range larger I get this error. Using breakpoints I discovered the error occurs in this portion of code
For iColl = (iReportCollumns + 2) To MaxY
xlApp.Cells(x, iColl) = "=SUM(" & GetColumnName(iColl) & (x + 1) & ":" & GetColumnName(iColl) & (x + iRowsPerRecord) & ")"
Next iColl
Since this is for work, I'm not able to reveal a lot of the code so I'll try to explain in good enough detail what's going on here. If you need more code, let me know and I'll see what I can release. The report has locations which each have multiple (but the same) sale types. For each sale type the report displays by month the total sales.
So sales are grouped at the highest level into locations, with sub groups for each sale type, these are displayed as separate rows of the spreadsheet. The months are the columns of the spreadsheet. iReportCollumns + 2 represents basic information that is displayed for each location, so that the sales data starts in the columns after this. iColl represents the current column, iRowsPerRecord represents the number of sale types. In my test case there are three rows per record, five years for a total of 60 months, and iReportCollumns = 9, so there are a total of 71 columns per row. MaxY represents the number of columns per row, so 71 in this case. This bit of code creates a totals row for each location. I have two locations in my test case so that there are 6 rows of data and 2 rows of totals. The totals rows come before the data rows for each location.
Stepping through this for loop, I discovered that it stops when iColl = 52 while it is still working on the first totals row. So it is not even getting to the data rows before I get this error. However it does insert the column names for all of the columns, but it breaks once it tries to write the sum formulas. Is there some limit to how many columns I can insert into an excel sheet?
My alternative solution is to just limit it to only show a maximum of 24 months per report, which works for other similar reports. That solution is okay, but I'd rather allow the user to choose a larger date range if they so please.

Dlookup a value in a table then multiply it with a value in form field X = value in the form field Y

Hello I am using MS Access 2007
I have a table called Extraction Line it is similar to an order line table , within this table are the two fields of concern:
Field: Tonnage:Number data type
Field: worth:Currency data type
What I want to happen is
As soon a user enters the tonnage value
In the afterupdate event for the tonnage field a Dlookup will
look at the Resource table and find the Price field (currency data type)
It then multiplies the Resource table Price value with the tonnage amount field (e.g) $50 x 5 etc, the $250 value is then added to the worth field.
So far I cannot even get success on using dlookup to get a value from the resource table
My code is in the extraction line form at the afterupdate event for the tonnage field:
Private Sub Tonnage_AfterUpdate()
Dim X As Currency
X = DLookup("[Price]", "[Resource]", "Atomic Number" = "076")
'X= Nz(DLookup("[Price]", "[Resource]", "Atomic Number" = "076"), 0)
'X = DLookup("[Price]", "[Resource]", "[Atomic number] = Form![Atomic number]") * [Worth]
I wanted to test the simple part of get a value first before doing the multiply and the rest of the requirements but keep getting Null value errors.
I think I am getting Null value errors due to this explanation
Null Value is due to...
But of course there will be no value or nothing there as I want dlookup to go get the value first then carry out the maths.
Prior to this way I tried various validation rules within the Extraction Line form but received ?Name errors.
What is the best way to achieve the above. If I can get help to point me in the right direction I can go away and attempt this.
How about:
Private Sub Tonnage_AfterUpdate()
''It is probably best not to use Currency when you do not know what will
''be returned
Dim varX As Variant
varX = Nz(DLookup("[Price]", "[Resource]", "[Atomic Number] = 076"),0) * [Worth]
If you want to refer to the look-up as a field or control and [Atomic Number] is a numeric field:
varX = Nz(DLookup("[Price]", "[Resource]", "[Atomic Number] = " _
& MyNumber),0) * [Worth]
In parts:
varX = DLookup("[Price]", "[Resource]", "[Atomic Number] = " & MyNumber)
If varX > 0 then
MyAnswer = VarX * Me.Worth
End If

Problem sub-total Matrix with rdlc report in vb.NET

I have a matrix and I need to add the money earned this year and past years. However, I must remove the money spent in past years. I must have the separate amount per year and the total of these amounts. This is what gives my matrix:
Year
= Fields!Year.value =formatnumber((sum(Fields!Results.Value))-(sum(iif(
Fields!Year.value < Parameters!choosedYear.Value,
Fields!Moneyspent.value,0))), 2) & "$"
However, the subtotal gives me an error. What should I do?
P.S.: I already found that the subtotal gives me an error because it's not in the scope of the rowgroup1, but is there a way to get the scope in the subtotal? or can anybody find another way to do it?
try like this
=formatnumber(sum(Fields!Results.Value)-iif(
Fields!Year.value < Parameters!choosedYear.Value,
sum( Fields!Moneyspent.value), 0), 2) & "$"